Java Code Examples for android.content.pm.PackageManager#GET_ACTIVITIES
The following examples show how to use
android.content.pm.PackageManager#GET_ACTIVITIES .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SilentAutoUpdate.java From android-auto-updater-client with Apache License 2.0 | 6 votes |
private String get_main_activity() { PackageManager pm = context.getPackageManager(); String packageName = context.getPackageName(); try { final int flags = PackageManager.GET_ACTIVITIES; PackageInfo packageInfo = pm.getPackageInfo(packageName, flags); for( ActivityInfo ai : packageInfo.activities ) { if( ai.exported ) { return ai.name; } } } catch (NameNotFoundException e) { e.printStackTrace(); } Log_e(TAG, "get_main_activity() failed"); return ""; }
Example 2
Source File: ApkTargetMapping.java From GPT with Apache License 2.0 | 5 votes |
/** * generateActivityInfo * * @param p PackageParser.Package * @param pi PackageInfo * @param flags flags */ private void generateActivityInfo(PackageParser.Package p, PackageInfo pi, int flags) { PackageUserState state = new PackageUserState(); if ((flags & PackageManager.GET_ACTIVITIES) != 0) { int N = p.activities.size(); if (N > 0) { if ((flags & PackageManager.GET_DISABLED_COMPONENTS) != 0) { pi.activities = new ActivityInfo[N]; } else { int num = 0; for (int i = 0; i < N; i++) { if (p.activities.get(i).info.enabled) num++; } pi.activities = new ActivityInfo[num]; } for (int i = 0, j = 0; i < N; i++) { final Activity activity = p.activities.get(i); if (activity.info.enabled || (flags & PackageManager.GET_DISABLED_COMPONENTS) != 0) { pi.activities[j++] = PackageParser.generateActivityInfo(activity, flags, state, 0); // try { // pi.activities[j++] = JavaCalls.callStaticMethodOrThrow(PackageParser.class, "generateActivityInfo", // activity, flags, state, 0); // } catch (Exception e) { // e.printStackTrace(); // } } } } } }
Example 3
Source File: RefreshInstalledListTask.java From apkextractor with GNU General Public License v3.0 | 4 votes |
@Override public void run(){ PackageManager manager=context.getApplicationContext().getPackageManager(); SharedPreferences settings= SPUtil.getGlobalSharedPreferences(context); int flag=0; if(settings.getBoolean(Constants.PREFERENCE_LOAD_PERMISSIONS,Constants.PREFERENCE_LOAD_PERMISSIONS_DEFAULT))flag|=PackageManager.GET_PERMISSIONS; if(settings.getBoolean(Constants.PREFERENCE_LOAD_ACTIVITIES,Constants.PREFERENCE_LOAD_ACTIVITIES_DEFAULT))flag|=PackageManager.GET_ACTIVITIES; if(settings.getBoolean(Constants.PREFERENCE_LOAD_RECEIVERS,Constants.PREFERENCE_LOAD_RECEIVERS_DEFAULT))flag|=PackageManager.GET_RECEIVERS; if(settings.getBoolean(Constants.PREFERENCE_LOAD_APK_SIGNATURE,Constants.PREFERENCE_LOAD_APK_SIGNATURE_DEFAULT))flag|=PackageManager.GET_SIGNATURES; if(settings.getBoolean(Constants.PREFERENCE_LOAD_SERVICES,Constants.PREFERENCE_LOAD_SERVICES_DEFAULT))flag|=PackageManager.GET_SERVICES; if(settings.getBoolean(Constants.PREFERENCE_LOAD_PROVIDERS,Constants.PREFERENCE_LOAD_PROVIDERS_DEFAULT))flag|=PackageManager.GET_PROVIDERS; final List<PackageInfo> list = new ArrayList<>(); synchronized (RefreshInstalledListTask.class){//加锁是在多线程请求已安装列表时PackageManager可能会抛异常 ParceledListSlice: Failure retrieving array; list.clear(); list.addAll(manager.getInstalledPackages(flag)); } Global.handler.post(new Runnable() { @Override public void run() { if(listener!=null)listener.onRefreshProgressStarted(list.size()); } }); for(int i=0;i<list.size();i++){ if(isInterrupted)return; PackageInfo info=list.get(i); boolean info_is_system_app=((info.applicationInfo.flags& ApplicationInfo.FLAG_SYSTEM)>0); final int current=i+1; Global.handler.post(new Runnable() { @Override public void run() { if(listener!=null)listener.onRefreshProgressUpdated(current,list.size()); } }); if(!flag_system&&info_is_system_app)continue; list_sum.add(new AppItem(context,info)); } if(isInterrupted)return; AppItem.sort_config=settings.getInt(Constants.PREFERENCE_SORT_CONFIG,0); Collections.sort(list_sum); synchronized (Global.app_list){ Global.app_list.clear(); Global.app_list.addAll(list_sum);//向全局list保存一个引用 } GetSignatureInfoTask.clearCache(); Global.handler.post(new Runnable() { @Override public void run() { if(listener!=null)listener.onRefreshCompleted(list_sum); } }); }
Example 4
Source File: ImportItem.java From apkextractor with GNU General Public License v3.0 | 4 votes |
public ImportItem(@NonNull Context context,@NonNull FileItem fileItem){ this.fileItem=fileItem; this.context=context; version_name=context.getResources().getString(R.string.word_unknown); version_code=context.getResources().getString(R.string.word_unknown); minSdkVersion=context.getResources().getString(R.string.word_unknown); targetSdkVersion=context.getResources().getString(R.string.word_unknown); drawable=context.getResources().getDrawable(R.drawable.icon_file); if(fileItem.getName().trim().toLowerCase().endsWith(".zip") ||fileItem.getName().trim().toLowerCase().endsWith(SPUtil.getCompressingExtensionName(context).toLowerCase())){ importType=ImportType.ZIP; drawable=context.getResources().getDrawable(R.drawable.icon_zip); } if(fileItem.getName().trim().toLowerCase().endsWith(".xapk")){ importType=ImportType.ZIP; drawable=context.getResources().getDrawable(R.drawable.icon_xapk); } if(fileItem.getName().trim().toLowerCase().endsWith(".apk")){ importType=ImportType.APK; PackageManager packageManager=context.getApplicationContext().getPackageManager(); if(fileItem.isFileInstance()){ try{ int flag=0; final SharedPreferences settings=SPUtil.getGlobalSharedPreferences(context); if(settings.getBoolean(Constants.PREFERENCE_LOAD_PERMISSIONS,Constants.PREFERENCE_LOAD_PERMISSIONS_DEFAULT))flag|=PackageManager.GET_PERMISSIONS; if(settings.getBoolean(Constants.PREFERENCE_LOAD_ACTIVITIES,Constants.PREFERENCE_LOAD_ACTIVITIES_DEFAULT))flag|=PackageManager.GET_ACTIVITIES; if(settings.getBoolean(Constants.PREFERENCE_LOAD_RECEIVERS,Constants.PREFERENCE_LOAD_RECEIVERS_DEFAULT))flag|=PackageManager.GET_RECEIVERS; if(settings.getBoolean(Constants.PREFERENCE_LOAD_APK_SIGNATURE,Constants.PREFERENCE_LOAD_APK_SIGNATURE_DEFAULT))flag|=PackageManager.GET_SIGNATURES; if(settings.getBoolean(Constants.PREFERENCE_LOAD_SERVICES,Constants.PREFERENCE_LOAD_SERVICES_DEFAULT))flag|=PackageManager.GET_SERVICES; if(settings.getBoolean(Constants.PREFERENCE_LOAD_PROVIDERS,Constants.PREFERENCE_LOAD_PROVIDERS_DEFAULT))flag|=PackageManager.GET_PROVIDERS; packageInfo=packageManager.getPackageArchiveInfo(fileItem.getPath(),flag); }catch (Exception e){e.printStackTrace();} if(packageInfo!=null){ packageInfo.applicationInfo.sourceDir=fileItem.getPath(); packageInfo.applicationInfo.publicSourceDir=fileItem.getPath(); drawable=packageInfo.applicationInfo.loadIcon(packageManager); version_name=packageInfo.versionName; version_code=String.valueOf(packageInfo.versionCode); if(Build.VERSION.SDK_INT>23){ minSdkVersion=String.valueOf(packageInfo.applicationInfo.minSdkVersion); } targetSdkVersion=String.valueOf(packageInfo.applicationInfo.targetSdkVersion); }else{ drawable=context.getResources().getDrawable(R.drawable.icon_apk); } }else{ drawable=context.getResources().getDrawable(R.drawable.icon_apk); } } length=fileItem.length(); lastModified =fileItem.lastModified(); }
Example 5
Source File: PluginClientManager.java From AndroidPlugin with MIT License | 4 votes |
/** * add a apk client. Before start a plugin Activity, we should do this * first.<br/> * NOTE : will only be called by host apk. * * @param dexPath */ public PluginClientInfo addPluginClient(String dexPath) { // when loadApk is called by host apk, we assume that plugin is invoked // by host. PackageManager packageManager = mContext.getPackageManager(); int flags = PackageManager.GET_ACTIVITIES | PackageManager.GET_CONFIGURATIONS | PackageManager.GET_INSTRUMENTATION | PackageManager.GET_PERMISSIONS | PackageManager.GET_PROVIDERS | PackageManager.GET_RECEIVERS | PackageManager.GET_SERVICES | PackageManager.GET_SIGNATURES; PackageInfo packageInfo = packageManager.getPackageArchiveInfo(dexPath, flags); if (packageInfo == null) { return null; } final String packageName = packageInfo.packageName; PluginClientInfo pluginPackage = mPluginClientPackages.get(packageName); if (pluginPackage == null) { DexClassLoader dexClassLoader = null; if (mPluginClientDexClassLoaders.containsKey(packageName)) { dexClassLoader = mPluginClientDexClassLoaders.get(packageName); } else { dexClassLoader = createDexClassLoader(dexPath, packageInfo.packageName, packageInfo.versionName); mPluginClientDexClassLoaders.put(packageName, dexClassLoader); } AssetManager assetManager = createAssetManager(dexPath); Resources resources = createResources(assetManager); pluginPackage = new PluginClientInfo(packageName, dexPath, dexClassLoader, assetManager, resources, packageInfo); mPluginClientPackages.put(packageName, pluginPackage); } if (!mPluginClientDexPaths.containsKey(packageName)) { mPluginClientDexPaths.put(packageName, dexPath); } return pluginPackage; }
Example 6
Source File: PluginManagerImpl.java From koala--Android-Plugin-Runtime- with Apache License 2.0 | 4 votes |
/** * 解析APK的manifest * * @param info * 插件信息 */ private void getPackageInfo(PluginInfo info) { int flags = PackageManager.GET_ACTIVITIES | PackageManager.GET_CONFIGURATIONS | PackageManager.GET_INSTRUMENTATION | PackageManager.GET_PERMISSIONS | PackageManager.GET_PROVIDERS | PackageManager.GET_RECEIVERS | PackageManager.GET_SERVICES | PackageManager.GET_SIGNATURES; // 需要获取Package对象,主要是处理隐式启动插件中的activity PackageParser parser = new PackageParser(info.apkPath); DisplayMetrics metrics = new DisplayMetrics(); metrics.setToDefaults(); File sourceFile = new File(info.apkPath); PackageParser.Package pack = parser.parsePackage(sourceFile, info.apkPath, metrics, 0); // 因为PackagePaser的generatePackageInfo方法不同版本参数相差太多,所以还是用packagemanager的api // 但这样导致APK被解析了两次,上面获取Package是一次 PackageInfo packageInfo = mContext.getPackageManager().getPackageArchiveInfo(info.apkPath, flags); info.packageName = packageInfo.packageName; info.mPackageObj = pack; info.mPackageInfo = packageInfo; ArrayList<PackageParser.Activity> activitys = pack.activities; int size = activitys.size(); for (int i = 0; i < size; i++) { mActivitys.addActivity(activitys.get(i)); } ArrayList<PackageParser.Service> services = pack.services; size = services.size(); for (int i = 0; i < size; i++) { mServices.addService(services.get(i)); } ArrayList<PackageParser.Provider> providers = pack.providers; size = providers.size(); for (int i = 0; i < size; i++) { Provider p = providers.get(i); String names[] = PATTERN_SEMICOLON.split(p.info.authority); for (int j = 0; j < names.length; j++) { mProviderInfoMap.put(names[i], p); } } }