Android Notification Action is not fired (PendingIntent)

前端 未结 9 1613
盖世英雄少女心
盖世英雄少女心 2020-12-30 02:39

I am trying to add an Notification action item in my app which is a music player. When a stream is started a notification should be triggered and an stop button for the stre

9条回答
  •  暖寄归人
    2020-12-30 02:56

    This is very late answer but it may help someone:

    You should choose the right kind of Pending intent based on the intent you want to run. Here are some Examples:

    For Activity use below:

    Intent i = new Intent(this, YourActivity.class);
    PendingIntent pi = PendingIntent.getActivity(this, 0, i, 0);
    

    For Service use below:

    Intent i = new Intent(this, YourService.class);
    PendingIntent pi = PendingIntent.getService(this, 0, i, 0);
    

    For Broadcast Receiver use below:

    Intent i = new Intent(this, YourReciver.class);
    PendingIntent pi = PendingIntent.getBroadcast(this, 0, i, 0);
    

    You may need to change the request code and Flags if required

提交回复
热议问题