iammert / RadioPlayerService

Android service library which uses AAC Player. Ready to use Radio Player Service.
254 stars 91 forks source link

Close notification along with application #42

Open luccastanan opened 7 years ago

luccastanan commented 7 years ago

How do I close the notification when the application is closed?

d2askif commented 7 years ago

Use startforground () in build notification

luccastanan commented 7 years ago

Just adding "startForeground(NOTIFICATION_ID, notification);" of method buildNotification() da class RadioPlayerService?

d2askif commented 7 years ago

Yp that should work. It shows the notification as long as your media is running

luccastanan commented 7 years ago

But it does not work, does it need some flag?

Sarun1001 commented 7 years ago

Hi, Add " RadioManager.getService().cancelNotification();" in your Activities on onDestroy()

public void onDestroy() {

        super.onDestroy();
        RadioManager.getService().cancelNotification();

    }
itskrsna commented 7 years ago

Hello ,

Is this able to get working ?

@luccastanan can you help out ?

MaheshKumarPrajapati commented 6 years ago
  1. make one service like this

public class OnClearFromRecentService extends Service {

@Override public IBinder onBind(Intent intent) { return null; }

@Override public int onStartCommand(Intent intent, int flags, int startId) { Log.d("ClearFromRecentService", "Service Started"); return START_NOT_STICKY; }

@Override public void onDestroy() { super.onDestroy(); Log.d("ClearFromRecentService", "Service Destroyed"); }

@Override public void onTaskRemoved(Intent rootIntent) { Log.e("ClearFromRecentService", "END"); //Code here NotificationManager nManager = ((NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE)); nManager.cancel(001); stopSelf(); }

  1. register this service in manifest.xml

service android:name=".OnClearFromRecentService" android:stopWithTask="false"

3.Then start this service on your radio activity

startService(new Intent(getBaseContext(), OnClearFromRecentService.class));

And now whenever you will clear your app from android recent Then this method onTaskRemoved() will execute.

AlaaZarifa commented 6 years ago

use this

@Override
  protected void onDestroy() {
    super.onDestroy();
   if (mRadioManager != null) {
      mRadioManager.disconnect();
      RadioManager.getService().stop();
    }
  }
Alexleet commented 5 years ago

use this

@Override
  protected void onDestroy() {
    super.onDestroy();
   if (mRadioManager != null) {
      mRadioManager.disconnect();
      RadioManager.getService().stop();
    }
  }

in RadioManager.getService().stop();

Supertypes of the following classes cannot be resolved. Please make sure you have the required dependencies in the classpath: