RadioPlayerService
RadioPlayerService copied to clipboard
Notification does not open activity
Hi there! I just noticed that the notification menu does not open up the activity when it' clicked. For example, if you click on the "home" button on your device and the notification is still on, I want to be able to click on it and navigate back to my app. After clicking the system menu still closes, but nothing happens after that (I believe that happens on most of the apps before the actual activity is opened). Need some help!
I also saw that notification remains opened even after the app gets closed. And I'm not having access anymore to the enableNotification method to fix this. =(
you need change "RadioPlayerService.java", because "onStartCommand" method can't word; need change "PendingIntent" for "getBroadcast" , then, you can listen this broadcast on you activity to launch anything.
???
Same problem here. Have you find any solution? Do you have any plans to update? Thank you!
That worked for me hope it helps :)
in the manifest file:
<receiver android:name=".MyBroadcast">
<intent-filter>
<action android:name="co.mobiwise.library.notification.radio.INTENT_OPENPLAYER" />
</intent-filter>
</receiver>
in MyBroadcast BroadcastReceiver:
@Override
public void onReceive(Context context, Intent intent) {
if (!isAppForground(context)) {
Intent newIntent = new Intent();
newIntent.setClassName("com.my.package", "com.my.package.MyActivity");
newIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
context.startActivity(newIntent);
}
}
public boolean isAppForground(Context mContext) {
ActivityManager am = (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningTaskInfo> tasks = am.getRunningTasks(1);
if (!tasks.isEmpty()) {
ComponentName topActivity = tasks.get(0).topActivity;
if (!topActivity.getPackageName().equals(mContext.getPackageName())) {
return false;
}
}
return true;
}
and finally added :
else if(action.equals(NOTIFICATION_INTENT_OPEN_PLAYER)){
Intent i = new Intent("co.mobiwise.library.notification.radio.INTENT_OPENPLAYER");
sendBroadcast(i);
}
to onStartCommand method in RadioPlayerService.java in the library.