react-native-audio-streaming icon indicating copy to clipboard operation
react-native-audio-streaming copied to clipboard

Player notification stays active but unresponsive when app is closed

Open gwitteveen opened this issue 8 years ago • 4 comments

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

gwitteveen avatar Mar 20 '17 09:03 gwitteveen

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

jerodb avatar Apr 27 '17 00:04 jerodb

not working #49

MichaelPintos avatar Apr 28 '17 13:04 MichaelPintos

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

jerodb avatar Apr 28 '17 17:04 jerodb

Hi, thx for help #80 work fine

El 28 abr. 2017, a las 14:46, Jero [email protected] escribió:

Hi @MichaelPintos https://github.com/MichaelPintos, did you add the created service to your app's AndroidManifest.xml?

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 { /** interface for clients that bind */ @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();
}

} 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; Finally declare the service in the app's AndroidManifest.xml: <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 app store a few days ago here: https://play.google.com/store/apps/details?id=com.am750&hl=en https://play.google.com/store/apps/details?id=com.am750&hl=en The only issue I couldn't resolve for this app was #80 https://github.com/tlenclos/react-native-audio-streaming/issues/80 . For rest of the repo, it's a great work by @tlenclos https://github.com/tlenclos — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/tlenclos/react-native-audio-streaming/issues/79#issuecomment-298062822, or mute the thread https://github.com/notifications/unsubscribe-auth/AZpDPpj0qBSvhmUtfW-GKyzopcnvX1_Xks5r0iXvgaJpZM4MiMR5.

MichaelPintos avatar May 26 '17 13:05 MichaelPintos