Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Player notification stays active but unresponsive when app is closed #79

Open
gwitteveen opened this issue Mar 20, 2017 · 4 comments
Open

Comments

@gwitteveen
Copy link

The player notification stays in the notification screen when the app is closed, but becomes unresponsive as in the play button doesn't work and the close button doesn't work.

You would expect the notification to be removed when the app is closed or at least be able to dismiss the notification.

I thought it might due to the way I implemented react-native-audio-streaming, but I checked LaCaveWebradio from the Play store and there the issue seems to persist.

Tested on Android 7.0

@jerodb
Copy link

jerodb commented Apr 27, 2017

@gwitteveen, the solution @samyachour proposes in #49 fixes the problem.

@MichaelPintos
Copy link

not working #49

@jerodb
Copy link

jerodb commented Apr 28, 2017

Hi @MichaelPintos, did you add the created service to your app's AndroidManifest.xml?

  1. Create new Service (I called it OnTaskRemovedService). I created a new file with the following content:
package com.example;

import android.app.Service;
import android.os.IBinder;
import android.app.NotificationManager;
import android.content.Context;
import android.content.Intent;

public class OnTaskRemovedService extends Service {
    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }

    @Override
    public void onTaskRemoved(Intent rootIntent) {
        super.onTaskRemoved(rootIntent);
        NotificationManager nManager = ((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE));
        nManager.cancelAll();
    }
}
  1. Start service in MainActivity.java:
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        startService(new Intent(this, OnTaskRemovedService.class));
    }

Don't forget to import Intent and Bundle into your MainActivity.java:

import android.content.Intent;
import android.os.Bundle;
  1. Finally add the service in the app's AndroidManifest.xml like this:
<service android:name="com.example.OnTaskRemovedService" android:stopWithTask="false" />

In all cases replace com.example with com.whateverYourApp

This worked for me. You can see a working example I uploaded to the play store a few days ago here: https://play.google.com/store/apps/details?id=com.am750&hl=en
The only issue I couldn't resolve for this app was #80 . For the rest of the repo, it's a great work by @tlenclos

@MichaelPintos
Copy link

MichaelPintos commented May 26, 2017 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants