so far I have been able to create custom notification when my player starts to play, but the problem is whenever i click the notification button that not only stops the media player button changes the button to stop icon.
But the thing is to achieve this i have to bring back the entire application from the dead and its kind of annoying when user click stop button in notification the entire application just resurfaces.
I am using intent to make a call on MainActivty that stops the player as well as updates the notification bar that the player has stopped.
There seems to be only normal examples of notification like displaying simple info and dismissing the notification on click of button. Pulling my hair for 5 days can some one help me with this! PLEASE ?
PS: i don't want to use the MediaStyle notification.
You can use Activity without UI.
public class NotificationActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//do your stuff
finish();//end activity
}
public static PendingIntent getViewIntent(int id){
Intent intent = new Intent(AppContext.context, NotificationActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
return PendingIntent.getActivity(AppContext.context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
}
}
In your manifest :
<activity
android:name=".NotificationActivity"
android:taskAffinity=""
android:excludeFromRecents="true"
android:theme="@android:style/Theme.NoDisplay">
</activity>
And inside NotificationBuilder
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(AppContext.context);
PendingIntent resultPendingIntent = NotificationActivity.getViewIntent(id);
mBuilder.setContentIntent(resultPendingIntent);
To update your notification with new icons you have to recreate custom notification with your desired icons and show notification again using same notification id.
NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
int notificationID =100;// this ID has to be same as your previuos ID
// mId allows you to update the notification later on.
mNotificationManager.notify(notificationID, mBuilder.build());