Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
 Android教程網 >> Android技術 >> 關於Android編程 >> android快捷卸載第三方應用

android快捷卸載第三方應用

編輯:關於Android編程

1、需要的權限: <uses-permission android:name="com.android.launcher.permission.READ_SETTINGS" /> 2、獲取所有應用 public List<ResolveInfo> getAllPagckage(Context context) { PackageManager pm = context.getPackageManager();   Intent mainIntent = new Intent(Intent.ACTION_MAIN, null); mainIntent.addCategory(Intent.CATEGORY_LAUNCHER); // 通過查詢,獲得所有ResolveInfo對象. List<ResolveInfo> resolveInfoList = pm.queryIntentActivities( mainIntent, PackageManager.GET_GIDS); // 調用系統排序,根據name排序 Collections.sort(resolveInfoList, new ResolveInfo.DisplayNameComparator(pm)); return resolveInfoList; } 3、過濾出第三方應用 private void filterPackage(List<ResolveInfo> allPackageList) { if (!allPackageList.isEmpty()) { list.clear(); int size = allPackageList.size(); ResolveInfo resolveInfo = null; for (int i = 0; i < size; i++) { resolveInfo = allPackageList.get(i); // 第三方應用 if((resolveInfo.activityInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) <= 0) { list.add(resolveInfo); } } } } 4、卸載 (注:1、兩種方式均可;2、appPackage為resolveInfo.activityInfo.packageName) public void uninstallApp(Context context, String appPackage) { Uri packageURI = Uri.parse("package:" + appPackage);         //自定義卸載 // Intent uninstallIntent = new Intent(Intent.ACTION_DELETE, // packageURI); //((Activity)context).startActivityForResult(uninstallIntent, 0);         //調用系統自帶卸載操作進行卸載 Intent uninstallIntent = new Intent( Settings.ACTION_APPLICATION_DETAILS_SETTINGS, packageURI); context.startActivity(uninstallIntent); }
  1. 上一頁:
  2. 下一頁:
熱門文章
閱讀排行版
Copyright © Android教程網 All Rights Reserved