2015-07-01 23 views
0

美好的一天!從活動中刪除Android應用程序

Android SDK中是否有一些工具可用於從活動中刪除應用程序。特別是,我需要活動方法,即刪除其他應用程序具有相同的應用程序名稱,但其他包。

+0

我認爲唯一的可用選項是隱式意圖卸載軟件包。 http://stackoverflow.com/questions/7868460/implicit-intent-to-uninstall-application – DeeV

回答

0

如果你的意思「同名的應用程序」與在XML menifest爲您的應用程序的標籤定義相同標籤的應用程序,這snippest應該工作:

private void deleteAppByActivityName(@NonNull String myAppLabel,@NonNull Context context){ 
    try { 
     PackageManager pm = context.getPackageManager(); 
     Intent mainIntent = new Intent(Intent.ACTION_MAIN, null); 
     mainIntent.addCategory(Intent.CATEGORY_LAUNCHER); 
     List<ResolveInfo> dataInDevice = pm.queryIntentActivities(mainIntent, 0); 
     for (ResolveInfo resolveInfo : dataInDevice){ 
      String label = resolveInfo.loadLabel(pm).toString(); 
      if (label.equals(myAppLabel)) { //we find app with same name as ours 
       Intent intent = new Intent(Intent.ACTION_DELETE); 
       intent.setData(Uri.parse("package:" + resolveInfo.activityInfo.packageName)); 
       context.startActivity(intent); 
       break; 
      } 
     } 
    }catch (ActivityNotFoundException e){ 
     e.printStackTrace(); 
    } 

}

+0

非常感謝。這就是我需要的。 –

相關問題