With notification style you can change it just with recreating a new notify with new style .It cost small blink (like refresh). But works.
Make your objects public static for first step .
Example :
public static NotificationCompat.Builder mBuilder;
public static RemoteViews contentBigCustom;
public static RemoteViews contentSmallNotExpand;
public static RemoteViews contentBigCustomFROMCODE;
Next - make this line :
notification.contentView = contentBigCustom;
to looks like :
// in top
public static RemoteViews contentAny;
Maybe you are using onStartCommand to initial objects thas good...
if (IWANTNOTIFYSTYLE == 0) {
contentBigCustom = RemoteViews(this.getPackageName(),R.layout.notificationBig);
}
else {
contentBigCustomFROMCODE = RemoteViews(this.getPackageName(),R.layout.notificationBig);
}
contentSmallNotExpand = RemoteViews(this.getPackageName(),R.layout.notificationSmall);
contentBigCustomFROMCODE = RemoteViews(this.getPackageName(),R.layout.notificationBig);
mBuilder = new NotificationCompat.Builder(this);
mBuilder.setDefaults(Notification.DEFAULT_ALL);
mBuilder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC);
mBuilder.setSmallIcon(R.drawable.play);
mBuilder.setContentText("This text is not in function but its needed to create notify");
mBuilder.setLargeIcon(icon);
mBuilder.setPriority(Notification.PRIORITY_MAX);
mBuilder.setContent(contentSmallNotExpand);
mBuilder.setCustomBigContentView(contentBigCustom);
After notify exe line :
mNotificationManager.notify(0, mBuilder.build());
put :
stopSelf() //To kill services.
When you want to change style start again services and put action id for style 1 2 .. n .
It look like refresh because we recreate new notify bar.
This is only way 100% for now!
If somebody think diferent please post me link to the app example.
You can make Activity object also public static .
Its is very easy now to control any combination :
Service - Activity
Service - BroadcastReceiver
BroadcastReceiver - Activity
But! :
Service1.contentNotify.setImageViewResource(R.id.NOTYFY_BTN, R.drawable.stop);
...
setImageViewResource Cant use this line for notification or any other style changes methods.
Only way is to create service , put on startCommand CREATE_NOTIFY()
Find from intent action name what notify.xml you want to load .
After notify build and add close service , then from broadcast call :
Intent serviceIntent = new Intent("WITHSTOP");
serviceIntent.putExtra("WITHSTOP", "1");
// must be MyApp extend Application reason : from broadcaster you cant access getContext and startService etc.
MyApp.getInstance().startService(serviceIntent);
Looks like :
public class MyApp extends Application {
private static MyApp instance;
public static MyApp getInstance() {
return instance;
}
public static Context getContext(){
return instance;
// or return instance.getApplicationContext();
}
@Override
public void onCreate() {
instance = this;
super.onCreate();
}
}
...