从ResolveInfo获取活动列表

时间:2015-04-15 09:24:56

标签: java android android-intent

问题是在特定的包中,有几个使用特定意图的活动,我想要所有这些活动的列表。

如果我使用

infos.activityInfo.applicationInfo.className

它只给我主要活动或null。

以下是我得到的例子:

09-11 04:46:31.628: I/User Interface(6779): name: Internet -com.android.browser.Browser
09-11 04:46:31.628: I/User Interface(6779): name: Internet -com.android.browser.Browser
09-11 04:46:31.628: I/User Interface(6779): name: Calendar -com.android.calendar.CalendarApplication
09-11 04:46:31.628: I/User Interface(6779): name: Calendar Storage -null
09-11 04:46:31.628: I/User Interface(6779): name: Calendar Storage -null
09-11 04:46:31.638: I/User Interface(6779): name: Camera -null
09-11 04:46:31.638: I/User Interface(6779): name: Cell Broadcast -com.android.cellbroadcastreceiver.CellBroadcastReceiverApp
09-11 04:46:31.638: I/User Interface(6779): name: Contacts -com.android.contacts.ContactsApplication
09-11 04:46:31.638: I/User Interface(6779): name: Contacts -com.android.contacts.ContactsApplication
09-11 04:46:31.638: I/User Interface(6779): name: Contacts -com.android.contacts.ContactsApplication
09-11 04:46:31.638: I/User Interface(6779): name: Contacts -com.android.contacts.ContactsApplication
09-11 04:46:31.638: I/User Interface(6779): name: Contacts -com.android.contacts.ContactsApplication
09-11 04:46:31.638: I/User Interface(6779): name: Contacts -com.android.contacts.ContactsApplication
09-11 04:46:31.648: I/User Interface(6779): name: EasyHome -com.lge.easyhome.LauncherApplication
09-11 04:46:31.658: I/User Interface(6779): name: File Manager -null
09-11 04:46:31.658: I/User Interface(6779): name: Gallery -com.android.gallery3d.app.GalleryAppImpl
09-11 04:46:31.658: I/User Interface(6779): name: Gallery -com.android.gallery3d.app.GalleryAppImpl
09-11 04:46:31.658: I/User Interface(6779): name: Home -com.lge.launcher2.LauncherApplication

您可以看到多次弹出应用程序名称但活动相同。这是什么意思?我是否认为这个意图被用于多个活动?如果是,那么有没有办法获取所有这些活动?

这是我写的代码。

Intent mainIntent = new Intent();
    mainIntent.setAction(Intent.ACTION_MAIN);        
    mainIntent.setType("text/plain");
    List<ResolveInfo> pkgAppsList = getApplicationContext().getPackageManager().queryIntentActivities( mainIntent, 0);

    int size = pkgAppsList.size();        
    Log.i(TAG, "Size: " + size);
    for(ResolveInfo info : pkgAppsList){

        String name = info.activityInfo.applicationInfo.loadLabel(getPackageManager()).toString();

        Log.i(TAG, "name: " + name + " -" + info.activityInfo.applicationInfo.className);
    }

1 个答案:

答案 0 :(得分:0)

  > Am I correct in thinking that this intent is being 
  > used in multiple activities?

意图可以匹配多个活动。你的例子应该列出所有

带有contentfilter contenttype“text / plain”的主要活动

有关工作示例,请参阅intent-intercept.. Explode.java中的方法checkAndShowMatchingActivites()

相关问题