Receiving broadcast from notification on Android Oreo

后端 未结 2 2007
鱼传尺愫
鱼传尺愫 2021-01-11 13:18

I have a custom button in a sticky notification.
I used to attach a PendingIntent to it for receiving button clicks:

Intent intent = new I         


        
2条回答
  •  长发绾君心
    2021-01-11 14:04

    Never use an implicit Intent when an explicit Intent will work.

    Replace:

    Intent intent = new Intent();
    
    intent.setAction("com.example.app.intent.action.BUTTON_CLICK");
    

    with:

    Intent intent = new Intent(this, NotificationActionReceiver.class);
    

    And remove the from the NotificationActionReceiver element.

提交回复
热议问题