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」。 –