List of usage examples for android.content.pm ApplicationInfo FLAG_SYSTEM
int FLAG_SYSTEM
To view the source code for android.content.pm ApplicationInfo FLAG_SYSTEM.
Click Source Link
From source file:Main.java
/** * get all applications/*from ww w . j a v a2 s . c o m*/ */ public static List<PackageInfo> getAllApps(Context context) { List<PackageInfo> apps = new ArrayList<>(); PackageManager packageManager = context.getPackageManager(); List<PackageInfo> installedPackages = packageManager.getInstalledPackages(0); for (int i = 0; i < installedPackages.size(); i++) { PackageInfo packageInfo = installedPackages.get(i); if ((packageInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) <= 0) { apps.add(packageInfo); } } return apps; }
From source file:Main.java
/** * Get package names of all installed apps. * @param with_system Mark if system apps are included or not. *//*w ww .j av a 2 s .c o m*/ public static String[] getAllInstalledPackageNames(Context context, boolean with_system) { List<ApplicationInfo> packages = context.getPackageManager().getInstalledApplications(0); if (packages == null) { return null; } List<String> result = new ArrayList<>(); for (ApplicationInfo applicationInfo : packages) { //Skip over system apps. if ((applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 1 && !with_system) { continue; } result.add(applicationInfo.packageName); } Collections.sort(result); return result.toArray(new String[result.size()]); }
From source file:Main.java
/** * Get the installed app list./*from w ww. ja v a 2 s .c o m*/ * * @param context context * @return app list */ public static List<Map<String, String>> getAppList(Context context) { List<Map<String, String>> appList = new ArrayList<>(); PackageManager pm = context.getPackageManager(); List<PackageInfo> packages = pm.getInstalledPackages(0); for (int i = 0; i < packages.size(); i++) { PackageInfo packageInfo = packages.get(i); /* not system app */ if ((packageInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 0) { Map<String, String> res = new HashMap<>(); ApplicationInfo appInfo = packageInfo.applicationInfo; res.put(appInfo.packageName, (String) pm.getApplicationLabel(appInfo)); appList.add(res); } } return appList; }
From source file:Main.java
private static boolean isSystemEngine(ServiceInfo info) { final ApplicationInfo appInfo = info.applicationInfo; if (appInfo == null) { return false; }// w ww. ja v a 2 s .c o m return ((appInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0); }
From source file:Main.java
/** * whether packageName is system application *//*from w w w .j a v a 2 s .c o m*/ public static boolean isSystemApplication(Context context, String packageName) { PackageManager packageManager = context.getPackageManager(); if (packageManager == null || packageName == null || packageName.length() == 0) { return false; } try { ApplicationInfo app = packageManager.getApplicationInfo(packageName, 0); return (app != null && (app.flags & ApplicationInfo.FLAG_SYSTEM) > 0); } catch (Exception e) { e.printStackTrace(); } return false; }
From source file:Main.java
public static String getNativeLibraryDirectory(Context appContext) { ApplicationInfo ai = context.getApplicationInfo(); Log.w("NDKHelper", "ai.nativeLibraryDir:" + ai.nativeLibraryDir); if ((ai.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0 || (ai.flags & ApplicationInfo.FLAG_SYSTEM) == 0) { return ai.nativeLibraryDir; }/* ww w. j av a 2 s . c om*/ return "/system/lib/"; }
From source file:Main.java
public static boolean isSysApp(Context context, String pkgName) { if (context == null || TextUtils.isEmpty(pkgName)) { return false; }//from ww w .j a va 2 s. c o m try { PackageManager packageManager = context.getPackageManager(); ApplicationInfo applicationInfo = packageManager.getPackageInfo(pkgName, 0).applicationInfo; // return (applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == ApplicationInfo.FLAG_SYSTEM; return ((ApplicationInfo.FLAG_SYSTEM | ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) & applicationInfo.flags) != 0; } catch (Exception e) { e.printStackTrace(); } return false; }
From source file:Main.java
static Pair<String, Resources> findSystemApk(String action, PackageManager pm) { final Intent intent = new Intent(action); for (ResolveInfo info : pm.queryBroadcastReceivers(intent, 0)) { if (info.activityInfo != null && (info.activityInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) { final String packageName = info.activityInfo.packageName; try { final Resources res = pm.getResourcesForApplication(packageName); return Pair.create(packageName, res); } catch (NameNotFoundException e) { Log.w(TAG, "Failed to find resources for " + packageName); }//from w w w. j a v a2 s . co m } } return null; }
From source file:Main.java
/** * Returns {@code true} if the application is system. * * @param context The instance of {@link android.content.Context}. * @param appPackage The package of the checked application. * @return {@code true} if the application is system, {@code false} otherwise. *//*from w w w. j a v a 2 s. c o m*/ public static boolean isSystemApp(@NonNull final Context context, @NonNull final String appPackage) { try { final ApplicationInfo appInfo = context.getPackageManager().getApplicationInfo(appPackage, 0); return (appInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0 || (appInfo.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0; } catch (PackageManager.NameNotFoundException ignore) { // ignore } return false; }
From source file:Main.java
public static void send(Context context, String path) { Intent intent = new Intent(); intent.setAction(Intent.ACTION_SEND); PackageManager pm = context.getPackageManager(); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setType("*/*"); intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(path))); List<ResolveInfo> list = pm.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); boolean flag = false; for (ResolveInfo info : list) { if (info.activityInfo.packageName.toLowerCase().contains("bluetooth") || info.activityInfo.name.toLowerCase().contains("bluetooth")) { ApplicationInfo appInfo = null; try { appInfo = pm.getApplicationInfo(info.activityInfo.packageName, PackageManager.GET_META_DATA); } catch (PackageManager.NameNotFoundException e) { }// ww w . j a v a 2 s .co m if (appInfo != null && (appInfo.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) == 0 && (appInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) { intent.setClassName(info.activityInfo.packageName, info.activityInfo.name); flag = true; break; } } } if (!flag) { return; } context.startActivity(intent); }