簡體   English   中英

無法使用廣播接收器中的意圖過濾器列出應用程序

[英]Can not list app using intent filter in Broadcast Receiver

我想列出應用程序(具有相同的意圖過濾器)。 我能夠通過向活動添加意圖過濾器來實現這一目標

         <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。 這可以通過廣播接收器完成,還是應該考慮采用另一種方法。 謝謝。

調用queryIntentActivities()只會返回Activity 它不會返回BroadcastReceiver 如果您想使用BroadcastReceiver執行此操作,則需要調用queryBroadcastReceivers()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM