Search in sources :

Example 21 with PackageManager

use of android.content.pm.PackageManager in project cw-advandroid by commonsguy.

the class TJDetect method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ActivityManager am = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
    HashSet<CharSequence> runningPackages = new HashSet<CharSequence>();
    for (ActivityManager.RunningAppProcessInfo proc : am.getRunningAppProcesses()) {
        for (String pkgName : proc.pkgList) {
            runningPackages.add(pkgName);
        }
    }
    PackageManager mgr = getPackageManager();
    ArrayList<CharSequence> scary = new ArrayList<CharSequence>();
    for (PackageInfo pkg : mgr.getInstalledPackages(PackageManager.GET_PERMISSIONS)) {
        if (PackageManager.PERMISSION_GRANTED == mgr.checkPermission(android.Manifest.permission.SYSTEM_ALERT_WINDOW, pkg.packageName)) {
            if (PackageManager.PERMISSION_GRANTED == mgr.checkPermission(android.Manifest.permission.INTERNET, pkg.packageName)) {
                if (runningPackages.contains(pkg.packageName)) {
                    scary.add(mgr.getApplicationLabel(pkg.applicationInfo));
                }
            }
        }
    }
    setListAdapter(new ArrayAdapter(this, android.R.layout.simple_list_item_1, scary));
}
Also used : PackageManager(android.content.pm.PackageManager) PackageInfo(android.content.pm.PackageInfo) ArrayList(java.util.ArrayList) ActivityManager(android.app.ActivityManager) ArrayAdapter(android.widget.ArrayAdapter) HashSet(java.util.HashSet)

Example 22 with PackageManager

use of android.content.pm.PackageManager in project cw-omnibus by commonsguy.

the class Nukesalot method buildAdapter.

private AppAdapter buildAdapter() {
    HashSet<String> runningPackages = new HashSet<String>();
    for (ActivityManager.RunningAppProcessInfo proc : am.getRunningAppProcesses()) {
        for (String pkg : proc.pkgList) {
            runningPackages.add(pkg);
        }
    }
    PackageManager pm = getPackageManager();
    List<ApplicationInfo> apps = new ArrayList<ApplicationInfo>();
    for (ApplicationInfo app : pm.getInstalledApplications(0)) {
        if (runningPackages.contains(app.packageName)) {
            apps.add(app);
        }
    }
    Collections.sort(apps, new ApplicationInfo.DisplayNameComparator(pm));
    return (new AppAdapter(pm, apps));
}
Also used : PackageManager(android.content.pm.PackageManager) ArrayList(java.util.ArrayList) ApplicationInfo(android.content.pm.ApplicationInfo) ActivityManager(android.app.ActivityManager) HashSet(java.util.HashSet)

Example 23 with PackageManager

use of android.content.pm.PackageManager in project UltimateAndroid by cymcsg.

the class PackageUtils method appInstalledOrNot.

public static boolean appInstalledOrNot(Context context, String uri) {
    PackageManager pm = context.getPackageManager();
    boolean app_installed = false;
    try {
        pm.getPackageInfo(uri, PackageManager.GET_ACTIVITIES);
        app_installed = true;
    } catch (PackageManager.NameNotFoundException e) {
        app_installed = false;
    }
    return app_installed;
}
Also used : PackageManager(android.content.pm.PackageManager) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException)

Example 24 with PackageManager

use of android.content.pm.PackageManager in project RocooFix by dodola.

the class RocooSoFix method getApplicationInfo.

private static ApplicationInfo getApplicationInfo(Context context) throws PackageManager.NameNotFoundException {
    PackageManager pm;
    String packageName;
    try {
        pm = context.getPackageManager();
        packageName = context.getPackageName();
    } catch (RuntimeException e) {
        /*
             * Ignore those exceptions so that we don't break tests relying on Context like a
             * android.test.mock.MockContext or a android.content.ContextWrapper with a null base Context.
             */
        Log.w(TAG, "Failure while trying to obtain ApplicationInfo from Context. " + "Must be running in test mode. Skip patching.", e);
        return null;
    }
    if (pm == null || packageName == null) {
        // This is most likely a mock context, so just return without patching.
        return null;
    }
    ApplicationInfo applicationInfo = pm.getApplicationInfo(packageName, PackageManager.GET_META_DATA);
    return applicationInfo;
}
Also used : PackageManager(android.content.pm.PackageManager) ApplicationInfo(android.content.pm.ApplicationInfo)

Example 25 with PackageManager

use of android.content.pm.PackageManager in project RocooFix by dodola.

the class RocooFix method getApplicationInfo.

private static ApplicationInfo getApplicationInfo(Context context) throws NameNotFoundException {
    PackageManager pm;
    String packageName;
    try {
        pm = context.getPackageManager();
        packageName = context.getPackageName();
    } catch (RuntimeException e) {
        /* Ignore those exceptions so that we don't break tests relying on Context like
             * a android.test.mock.MockContext or a android.content.ContextWrapper with a null
             * base Context.
             */
        Log.w(TAG, "Failure while trying to obtain ApplicationInfo from Context. " + "Must be running in test mode. Skip patching.", e);
        return null;
    }
    if (pm == null || packageName == null) {
        // This is most likely a mock context, so just return without patching.
        return null;
    }
    ApplicationInfo applicationInfo = pm.getApplicationInfo(packageName, PackageManager.GET_META_DATA);
    return applicationInfo;
}
Also used : PackageManager(android.content.pm.PackageManager) ApplicationInfo(android.content.pm.ApplicationInfo)

Aggregations

PackageManager (android.content.pm.PackageManager)1429 Intent (android.content.Intent)483 ResolveInfo (android.content.pm.ResolveInfo)449 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)345 ApplicationInfo (android.content.pm.ApplicationInfo)249 PackageInfo (android.content.pm.PackageInfo)248 ComponentName (android.content.ComponentName)239 ArrayList (java.util.ArrayList)156 ActivityInfo (android.content.pm.ActivityInfo)135 IOException (java.io.IOException)126 RemoteException (android.os.RemoteException)105 IPackageManager (android.content.pm.IPackageManager)93 Drawable (android.graphics.drawable.Drawable)93 Resources (android.content.res.Resources)90 PendingIntent (android.app.PendingIntent)71 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)69 Context (android.content.Context)63 Bundle (android.os.Bundle)60 HashMap (java.util.HashMap)53 ServiceInfo (android.content.pm.ServiceInfo)46