Android Notification Action is not fired (PendingIntent)

前端 未结 9 1498
盖世英雄少女心
盖世英雄少女心 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 03:12

    For me, the solution was to set the flags of the intent :

    resultIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
                    Intent.FLAG_ACTIVITY_CLEAR_TASK);
    
    0 讨论(0)
  • 2020-12-30 03:20

    I ran into this problem today and it was caused by the activity not being registered or added to AndroidManifest.xml. I thought I had it in there but it wasn't. Also, no errors were being logged by trying to invoke the action with its intent.

    I figured this out by creating an intent and then calling startAcitivty(intent) without using a notification. It then gave me an error stating the activity was likely missing from the manifest.

    If none of the other answers solve your problem then hopefully this will. Usually tricky problems are the result of something simple and silly.

    0 讨论(0)
  • 2020-12-30 03:21

    More than using broadcast receiver, you should use a service and declare a new action in your service this way:

    public final String ACTION_STOP = "yourpackagename.ACTION_STOP";
    

    And then create your intents like this:

    Intent stopIntent = new Intent(this, YourService.class).setAction(YourService.ACTION_STOP);
    PendingIntent stopPendingIntent = PendingIntent.getService(this, 0, stopIntent, 0);
    

    Of course, stop playback in your service's function startCommand, if the intent's action equals ACTION_STOP.

    This should do the trick ;)

    0 讨论(0)
提交回复
热议问题