Search in sources :

Example 11 with PackageItemInfo

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;
}
Also used : PackageManager(android.content.pm.PackageManager) ArrayList(java.util.ArrayList) ApplicationInfo(android.content.pm.ApplicationInfo) PackageItemInfo(android.content.pm.PackageItemInfo) Drawable(android.graphics.drawable.Drawable)

Example 12 with PackageItemInfo

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());
}
Also used : PackageManager(android.content.pm.PackageManager) PackageInfo(android.content.pm.PackageInfo) PackageItemInfo(android.content.pm.PackageItemInfo) DefaultAppInfo(com.android.settings.applications.defaultapps.DefaultAppInfo) RadioButtonPreference(com.android.settings.widget.RadioButtonPreference) Test(org.junit.Test)

Example 13 with PackageItemInfo

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.");
    }
}
Also used : PackageManager(android.content.pm.PackageManager) PackageItemInfo(android.content.pm.PackageItemInfo) ComponentName(android.content.ComponentName)

Aggregations

PackageItemInfo (android.content.pm.PackageItemInfo)13 PackageManager (android.content.pm.PackageManager)13 ApplicationInfo (android.content.pm.ApplicationInfo)6 Drawable (android.graphics.drawable.Drawable)6 ArrayList (java.util.ArrayList)6 PackageInfo (android.content.pm.PackageInfo)5 DefaultAppInfo (com.android.settings.applications.defaultapps.DefaultAppInfo)5 RadioButtonPreference (com.android.settings.widget.RadioButtonPreference)5 Test (org.junit.Test)5 ComponentName (android.content.ComponentName)2