当用户选择What is the purpose of IntentSender?和Get IntentSender object for createChooser method in Android所述的选择器时,我正在尝试播放。
我在帖子中创建选择器作为描述符:
Intent intent = new Intent(Intent.ACTION_SEND)
.putExtra(Intent.EXTRA_TEXT, "This is my text to send.")
.setType("text/plain");
Intent receiver = new Intent(this, BroadcastTest.class)
.putExtra("test", "test");
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, receiver, PendingIntent.FLAG_UPDATE_CURRENT);
Intent chooser = Intent.createChooser(intent, "test", pendingIntent.getIntentSender());
startActivity(chooser);
并在我的AndroidManifest中注册我的BroadcastReceiver:
<receiver
android:name="com.migore.intentsender.BroadcastTest"
android:enabled="true"
android:exported="true">
<intent-filter android:priority="1">
<action android:name="com.migore.intentsender.intent.TEST" />
</intent-filter>
</receiver>
然而,我的接收器从未被调用过。我已经尝试在代码中注册接收器,但它也没有用。我错过了什么?
答案 0 :(得分:0)
你好用下面的代码
<receiver
android:name="com.migore.intentsender.BroadcastTest"
android:enabled="true"
android:exported="true">
<intent-filter>
<action droid:name="android.intent.extra.CHOSEN_COMPONENT" />
</intent-filter>
</receiver>