未从Chrome“自定义标签"菜单项单击“接收广播" [英] Broadcast not received from Chrome Custom Tab menu item click

查看:105
本文介绍了未从Chrome“自定义标签"菜单项单击“接收广播"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在片段中进行以下操作(为方便起见,此内容已精简):

I am doing the following within a Fragment (condensed for convenience):

intentBuilder = new CustomTabsIntent.Builder();
String label = "Test";
PendingIntent pendingIntent = createPendingIntent(ActionBroadcastReceiver.ACTION_TEST);
intentBuilder.addMenuItem(label, pendingIntent);

CustomTabActivityHelper.openCustomTab(
                    getActivity(), intentBuilder.build(), mUri, null);


private PendingIntent createPendingIntent(int actionSourceId) {
    Intent actionIntent = new Intent(getActivity().getApplicationContext(),
            ActionBroadcastReceiver.class);
    actionIntent.putExtra(ActionBroadcastReceiver.KEY_TEST, actionSourceId);

    return PendingIntent.getBroadcast(
            getActivity().getApplicationContext(), actionSourceId, actionIntent, 0);
}

然后我有一个扩展了BroadcastReceiverActionBroadCastReceiver类:

Then I have an ActionBroadCastReceiver class that extends BroadcastReceiver:

@Override
public void onReceive(Context context, Intent intent) {
    Log.d(ActionBroadcastReceiver.class.getSimpleName(), "Broadcast Received");

Toast.makeText(context, "Received", Toast.LENGTH_SHORT).show();
    }
}

单击菜单项时,我的日志呼叫没有出现,并且吐司消息也没有出现,这使我相信广播从未发送或接收.

My log call does not appear and neither does the toast message when the menu item is clicked, which leads me to believe the broadcast is never sent nor received.

推荐答案

尝试在广播中添加操作.

Try adding an action to your broadcast.

将其注册到清单文件中,如下所示:

Register it in manifest file like this:

<receiver android:name="com.example.app.MyReceiver" >
    <intent-filter>
        <action android:name="com.example.app.SOME_ACTION" />
    </intent-filter>
</receiver>

设置意图如下:

Intent actionIntent = new Intent("com.example.app.SOME_ACTION");

这篇关于未从Chrome“自定义标签"菜单项单击“接收广播"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆