通知風格,你可以改變它只是重新創建一個新的風格的通知。它的成本很小(如刷新)。但工作。
使您的對象成爲公共靜態的第一步。
實施例:
public static NotificationCompat.Builder mBuilder;
public static RemoteViews contentBigCustom;
public static RemoteViews contentSmallNotExpand;
public static RemoteViews contentBigCustomFROMCODE;
下一個 - 使這條線:
notification.contentView = contentBigCustom;
來的樣子:
// in top
public static RemoteViews contentAny;
也許你正在使用onStartCommand初始對象全髖關節置換好...
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()
過度殺死服務。當你想要改變樣式再次啓動服務,並把樣式1 2的行動ID .. .. 它看起來像刷新,因爲我們重新創建新的通知欄。 現在這只是100%的方法! 如果有人認爲不同,請張貼我鏈接到應用程序的例子。
您可以使Activity對象也是靜態的。
它現在是很容易控制的任意組合:
服務 - 活動 服務 - 廣播接收器 廣播接收器 - 活動
但是! :
Service1.contentNotify.setImageViewResource(R.id.NOTYFY_BTN,R.drawable.stop);
...
setImageViewResource不能使用此行的通知或任何其他樣式改變方法。
唯一的方法是創建服務,換上啓動命令CREATE_NOTIFY() 從notify.xml要加載什麼意圖動作名稱查找。 通知後生成並添加貼心的服務,然後從廣播呼叫:
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);
的樣子:
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();
}
}
...
http://stackoverflow.com/questions/21237495/create -custom-大的通知 – duggu 2014-12-30 07:27:39