use of android.content.pm.PackageItemInfo in project zxingfragmentlib by mitoyarzun.
the class LoadPackagesAsyncTask method doInBackground.
@Override
protected List<AppInfo> doInBackground(Object... objects) {
List<AppInfo> labelsPackages = new ArrayList<>();
PackageManager packageManager = activity.getPackageManager();
Iterable<ApplicationInfo> appInfos = packageManager.getInstalledApplications(0);
for (PackageItemInfo appInfo : appInfos) {
String packageName = appInfo.packageName;
if (!isHidden(packageName)) {
CharSequence label = appInfo.loadLabel(packageManager);
Drawable icon = appInfo.loadIcon(packageManager);
if (label != null) {
labelsPackages.add(new AppInfo(packageName, label.toString(), icon));
}
}
}
Collections.sort(labelsPackages);
return labelsPackages;
}
use of android.content.pm.PackageItemInfo in project android_packages_apps_Settings by SudaMod.
the class WebViewAppPickerTest method testWebViewVersionAddedAfterLabel.
/**
* Ensure that the version name of a WebView package is displayed after its name in the
* preference title.
*/
@Test
public void testWebViewVersionAddedAfterLabel() throws PackageManager.NameNotFoundException {
PackageItemInfo mockPackageItemInfo = mock(PackageItemInfo.class);
mockPackageItemInfo.packageName = DEFAULT_PACKAGE_NAME;
when(mockPackageItemInfo.loadLabel(any())).thenReturn("myPackage");
DefaultAppInfo webviewAppInfo = mPicker.createDefaultAppInfo(mPackageManager, mockPackageItemInfo, "");
PackageInfo packageInfo = new PackageInfo();
packageInfo.versionName = "myVersionName";
PackageManager pm = mock(PackageManager.class);
when(pm.getPackageInfo(eq(DEFAULT_PACKAGE_NAME), anyInt())).thenReturn(packageInfo);
when(mPackageManager.getPackageManager()).thenReturn(pm);
RadioButtonPreference mockPreference = mock(RadioButtonPreference.class);
mPicker.bindPreference(mockPreference, DEFAULT_PACKAGE_NAME, webviewAppInfo, null);
mPicker.bindPreferenceExtra(mockPreference, DEFAULT_PACKAGE_NAME, webviewAppInfo, null, null);
verify(mockPreference, times(1)).setTitle(eq("myPackage myVersionName"));
verify(mockPreference, times(1)).setTitle(any());
}
use of android.content.pm.PackageItemInfo in project android-beacon-library by AltBeacon.
the class ScanJob method getJobIdFromManifest.
private static int getJobIdFromManifest(Context context, String name) {
PackageItemInfo info = null;
try {
info = context.getPackageManager().getServiceInfo(new ComponentName(context, ScanJob.class), PackageManager.GET_META_DATA);
} catch (PackageManager.NameNotFoundException e) {
/* do nothing here */
}
if (info != null && info.metaData != null && info.metaData.get(name) != null) {
int jobId = info.metaData.getInt(name);
LogManager.i(TAG, "Using " + name + " from manifest: " + jobId);
return jobId;
} else {
throw new RuntimeException("Cannot get job id from manifest. " + "Make sure that the " + name + " is configured in the manifest for the ScanJob.");
}
}
Aggregations