2017-08-28 72 views

回答

0

搜索ACTION_SENDACTION_VIEW並通過循環檢查哪個應用程序具有並從列表中排除它們。

public ArrayList<ResolveInfo> getApps() { 
    ArrayList<ResolveInfo> result = new ArrayList<>(); 

    Intent view = new Intent(); 
    view.setAction(android.content.Intent.ACTION_VIEW); 
    view.setDataAndType(Uri.fromFile(new File("sdcard/blah/blah/blah")), "*/*"); 

    Intent send = new Intent(); 
    send.setAction(Intent.ACTION_SEND); 
    send.setDataAndType(Uri.fromFile(new File("sdcard/blah/blah/blah")), "*/*"); 

    PackageManager packageManager = this.getPackageManager(); 
    List<ResolveInfo> actionView = packageManager.queryIntentActivities(view, 0); 
    List<ResolveInfo> actionSend = packageManager.queryIntentActivities(send, 0); 

    for (ResolveInfo viewItem : actionView) { 
     boolean notFound = true; 

     for (ResolveInfo sendItem : actionSend) { 

      if (viewItem.activityInfo.name.equals(sendItem.activityInfo.name)) 
       notFound = false; 

      if (notFound) 
       result.add(viewItem); 
     } 
    } 


    return result; 
} 
+0

謝謝。但它似乎不適合我。我的代碼是: Intent intent = new Intent(Intent.ACTION_VIEW); startActivity(intent); 通過這種方式,它調用一些應用程序是我不需要的。我想過濾這些應用程序。 – donald

+0

好吧,我明白了!問題不明確 – lvl4fi4

+0

@唐納德檢查我的更新 – lvl4fi4

相關問題