0

我正在尝试捕获自定义通知按钮上的点击操作。我想避免创建一个扩展BroadcastReciever. 为此,我在我的服务类中编码如下:

this.registerReceiver(new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            Log.v ("Myreceiver", "on click catch")
        }
    }, new IntentFilter("MyRemoteViewsBroadcast"));

PendingIntent pi = PendingIntent.getBroadcast(this, 0, new Intent("MyRemoteViewsBroadcast"), 0);
remoteviews.setOnClickPendingIntent(R.I'd. Button, pi);

但它不起作用。我失去了什么吗?

编辑:“它不起作用”我的意思是当我点击按钮时永远不会调用 OnReceive() 方法。(抱歉问题不完整)

4

1 回答 1

0

我才发现问题出在哪里!!!

代码完美运行!!!我在自己的代码中写道:

PendingIntent playPendingIntent = PendingIntent.**getService**( getApplicationContext(), NOTIFICATION_ID, new Intent("MyRemoteViewsBroadcast"), 0);

代替:

PendingIntent playPendingIntent = PendingIntent.**getBroadcast**( getApplicationContext(), NOTIFICATION_ID, new Intent("MyRemoteViewsBroadcast"), 0);

愚蠢的错误。我需要休息!带来不便敬请谅解。

于 2016-07-26T21:18:05.733 回答