3
我想列出应用程序(具有相同的意向过滤器)。我能够通过添加意图过滤到活动无法在广播接收器中使用意向过滤器列出应用程序
<activity
android:name=".Activities.MainActivity"
android:launchMode="singleTask"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateHidden|adjustNothing">
<intent-filter>
<action android:name="com.example.identifier" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="isApp" />
</intent-filter>
</activity>
实现这一目标,我可以检索与
String uri = "isApp:";
Intent intent = new Intent("com.example.identifier",
Uri.parse(uri));
PackageManager manager = getPackageManager();
List<ResolveInfo> list = manager.queryIntentActivities(intent, 0);
但是有这个意图的所有应用程序,这将启动活动使用该代码段中intentChoose所示,当:
Intent zoneIntent = new Intent("com.example.identifier",
Uri.parse(uri));
Intent openInChooser = Intent.createChooser(zoneIntent, "Complete Action with").setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(openInChooser);
但我想要这个调用广播接收器。所以,我搬到意图的广播接收机在AndroidManifest.xml中,如:
<receiver
android:name=".ExampleReceiver"
android:enabled="true">
<intent-filter>
<action android:name="com.example.identifier" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="isApp" />
</intent-filter>
</receiver>
,并返回应用程序的这一意图返回0的数量现在即使该应用程序仍是该设备上的片段。这可以用广播接收器来完成吗?或者我应该考虑另一种方法。谢谢。
但Intent zoneIntent = new Intent(“com.example.identifier”, Uri.parse(uri)); 意图openInChooser = Intent.createChooser(zoneIntent,“Complete Action with”)。setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(openInChooser);没有显示这个应用程序,不像当我在活动中使用intentfilter –
这是正确的,因为“选择器”只能找到“活动”,而不是“BroadcastReceiver”。 –