【问题标题】:onClick button in a custom notification自定义通知中的 onClick 按钮
【发布时间】:2016-07-26 19:44:02
【问题描述】:

我正在尝试捕捉自定义通知按钮上的点击操作。我想避免创建一个扩展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() 方法。 (抱歉问题不完整)

【问题讨论】:

  • “不起作用”是什么意思,您遇到的具体问题是什么?
  • 感谢您的快速答复!我的意思是点击时不会调用 onReceive() 方法,所以不会出现 Log...

标签: android notifications broadcastreceiver custom-notification


【解决方案1】:

我才意识到问题出在哪里!!!

代码完美运行!!!我用自己的代码写过:

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

代替:

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

愚蠢的错误。我需要休息!很抱歉给您带来不便。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-14
    • 2014-03-22
    相关资源
    最近更新 更多