安卓:从具有远程视窗多个通知更新的具体通知 [英] Android: update specific notification from multiple notifications which have remoteview
问题描述
我创建包含通知具有播放/暂停图标,应用程序,它。它的工作原理完美的,当有有仅仅只有一个通知其中只有一个通知ID,它仅通过一个notificationid改变播放/暂停图标,但也出现问题,多个通知。当有多个通知,每个通知具有播放/暂停图标。当我点击的通知中的一个播放/暂停图标,比它只能改变前通知图标从通知的堆栈。我知道这个问题是由于通知-ID,它的点击有任何notification.I想获得ID上的点击播放所有通知/暂停icon.I试图用pendingIntent内容的一些变化,但暂时还没有发现一些具体的解决方案。
I am creating application that contain notification which have play/pause icon , which. it works perfect when there have just only one notification which have just one notification id, it change play/pause icon through only one notificationid, but there have issue with multiple notification. When there have multiple notification, each notification have play/pause icon. when i click play/pause icon from one of the notification, than it only changing top notification icon from the stack of notification. i know this problem is due to notification-id which it got on click on any notification.I want to get id for all notification on click of play/pause icon.I have tried it with some changing of pendingIntent content , but not found yet some exact solution.
我想知道,有没有办法让notificationid通知,在点击了播放/那暂停图标?,这样我就可以改变图标或通过通知更新通知id.Need经过那里通知ID更新通知。
I want to know , is there way to get notificationid of notification,on click of play/pause icon of that?, So i can change the icon or update that notification through notification id.Need to update notification through there notification id.
我已经使用远程视图来获得服装设计的通知。在code低于
I have used remote-view to get costume layout in notification. the code is below
的通知code
RemoteViews mRemoteViews1 = null;
PendingIntent pendingIntent = null;
PendingIntent pendingIntent1 = null;
PendingIntent pendingIntent2 = null;
PendingIntent pendingIntent3 = null;
PendingIntent pendingIntent4 = null;
PendingIntent pendingIntent5 = null;
if (mRemoteViews1 == null) {
Log.d("LOG", "mRemoteViews is null");
mRemoteViews1 = new RemoteViews(getPackageName(),
R.layout.custom_notification);
} else {
if (mState == palyer.Paused || mState == palyer.Stopped) {
try {
Log.e("LOG", "State.Paused || State.Stopped");
mRemoteViews1.setImageViewResource(R.id.playpush,
R.drawable.playdetailfornoti); // play icon
} catch (Exception e) {}
} else if (mState == palyer.Playing) {
try {
Log.e("LOG", "State.Playing");
mRemoteViews1.setImageViewResource(R.id.playpush,
R.drawable.pushdetail); // pushicon
} catch (Exception e) {}
} else if (mState == palyer.Retrieving) {
try {
Log.e("LOG", "else Retrieving");
mRemoteViews1.setImageViewResource(R.id.playpush,
R.drawable.playdetailfornoti); // play icon
} catch (Exception e) {}
}
else {
try {
Log.e("LOG", "else");
mRemoteViews1.setImageViewResource(R.id.playpush,
R.drawable.pushdetail); // pushicon
} catch (Exception e) {}
}
}
Intent intent = new Intent(ACTION_TOGGLE_PLAYBACK);
Intent intent1 = new Intent(CLOSE_PUSH_NOTIFICATION);
Intent intent2 = new Intent(ACTION_NEXT);
Intent intent3 = new Intent(ACTION_PREVIOUS);
Intent intent4 = new Intent(ACTION_STOP);
Intent intent5 = new Intent(ACTION_PLAY_NOTIFICATION_START);
Intent newintent = new Intent(this, Splace.class);
newintent.putExtra("newsId",_id);
newintent.putExtra("message",title);
newintent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
Intent.FLAG_ACTIVITY_SINGLE_TOP);
newintent.setAction("actionstring" + System.currentTimeMillis());
pendingIntent = PendingIntent.getService(getApplicationContext(),
REQUEST_CODE_STOP, intent, PendingIntent.FLAG_UPDATE_CURRENT);
pendingIntent1 = PendingIntent.getService(getApplicationContext(), 0,
intent1, 0);
pendingIntent2 = PendingIntent.getService(getApplicationContext(),
REQUEST_CODE_STOP, intent2, PendingIntent.FLAG_UPDATE_CURRENT);
pendingIntent3 = PendingIntent.getService(getApplicationContext(),
REQUEST_CODE_STOP, intent3, PendingIntent.FLAG_UPDATE_CURRENT);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
newintent, 0);
pendingIntent4 = PendingIntent.getService(getApplicationContext(),
REQUEST_CODE_STOP, intent4, PendingIntent.FLAG_UPDATE_CURRENT);
pendingIntent5 = PendingIntent.getService(getApplicationContext(),
REQUEST_CODE_STOP, intent5, PendingIntent.FLAG_UPDATE_CURRENT);
mRemoteViews1.setTextViewText(R.id.playertitle,
MusicList.CurrentNotificationEntity.scrape_title);
mRemoteViews1
.setTextViewText(R.id.playerapaer, Base
.getNewsPaperName(Base.sharedPref.getString(
MusicList.CurrentNotificationEntity.newspaperID,
"Palpal")));
mRemoteViews1.setOnClickPendingIntent(R.id.forward, pendingIntent2);
mRemoteViews1.setOnClickPendingIntent(R.id.backword, pendingIntent3);
mRemoteViews1.setOnClickPendingIntent(R.id.playertitle, contentIntent);
mRemoteViews1.setOnClickPendingIntent(R.id.playerapaer, contentIntent);
mRemoteViews1.setOnClickPendingIntent(R.id.playerimage, contentIntent);
mRemoteViews1.setOnClickPendingIntent(R.id.playpush, pendingIntent);
mRemoteViews1.setOnClickPendingIntent(R.id.close, pendingIntent1);
Notification mNotification1 = new NotificationCompat.Builder(
getApplicationContext())
.setSmallIcon(R.drawable.ic_launcher)
.setWhen(System.currentTimeMillis())
.setPriority(Notification.PRIORITY_HIGH)
.setDeleteIntent(pendingIntent1)
.setAutoCancel(true)
.setContent(mRemoteViews1).setOngoing(false).build();
mNotificationManager.notify(Base.currentNotificationNo, mNotification1);
请帮我在此先感谢
推荐答案
多多尝试之后,我想通了,该解决方案通过改变一些code在悬而未决的意图,如下图所示code
After lot of try i figured out the solution by changing some code in pending intent, as shown in below code
我的code低于
public void UpdateNotificationfunction(int currentNotificationNo) {
RemoteViews mRemoteViews1 = null;
PendingIntent pendingIntent = null;
PendingIntent pendingIntent1 = null;
PendingIntent pendingIntent2 = null;
PendingIntent pendingIntent3 = null;
PendingIntent pendingIntent4 = null;
PendingIntent pendingIntent5 = null;
if (mRemoteViews1 == null) {
Log.d("LOG", "mRemoteViews is null");
mRemoteViews1 = new RemoteViews(getPackageName(),
R.layout.custom_notification);
} else {
if (mState == palyer.Paused || mState == palyer.Stopped) {
try {
Log.e("LOG", "State.Paused || State.Stopped");
mRemoteViews1.setImageViewResource(R.id.playpush,
R.drawable.playdetailfornoti); // play icon
} catch (Exception e) {}
} else if (mState == palyer.Playing) {
try {
Log.e("LOG", "State.Playing");
mRemoteViews1.setImageViewResource(R.id.playpush,
R.drawable.pushdetail); // pushicon
} catch (Exception e) {}
} else if (mState == palyer.Retrieving) {
try {
Log.e("LOG", "else Retrieving");
mRemoteViews1.setImageViewResource(R.id.playpush,
R.drawable.playdetailfornoti); // play icon
} catch (Exception e) {}
}
else {
try {
Log.e("LOG", "else");
mRemoteViews1.setImageViewResource(R.id.playpush,
R.drawable.pushdetail); // pushicon
} catch (Exception e) {}
}
}
Intent intent = new Intent(ACTION_TOGGLE_PLAYBACK);
Intent intent1 = new Intent(CLOSE_PUSH_NOTIFICATION);
Intent intent2 = new Intent(ACTION_NEXT);
Intent intent3 = new Intent(ACTION_PREVIOUS);
Intent intent4 = new Intent(ACTION_STOP);
Intent intent5 = new Intent(ACTION_PLAY_NOTIFICATION_START);
Intent newintent = new Intent(this, Splace.class);
newintent.putExtra("newsId",_id);
newintent.putExtra("message",title);
newintent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
Intent.FLAG_ACTIVITY_SINGLE_TOP);
newintent.setAction("actionstring" + System.currentTimeMillis());
pendingIntent = PendingIntent.getService(getApplicationContext(),
currentNotificationNo, intent, PendingIntent.FLAG_UPDATE_CURRENT); // changed here currentNotificationNo insted of REQUEST_CODE_STOP
pendingIntent1 = PendingIntent.getService(getApplicationContext(), 0,
intent1, 0);
pendingIntent2 = PendingIntent.getService(getApplicationContext(),
currentNotificationNo, intent2, PendingIntent.FLAG_UPDATE_CURRENT);// changed here currentNotificationNo insted of REQUEST_CODE_STOP
pendingIntent3 = PendingIntent.getService(getApplicationContext(),
currentNotificationNo, intent3, PendingIntent.FLAG_UPDATE_CURRENT);// changed here currentNotificationNo insted of REQUEST_CODE_STOP
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
newintent, 0);
pendingIntent4 = PendingIntent.getService(getApplicationContext(),
currentNotificationNo, intent4, PendingIntent.FLAG_UPDATE_CURRENT);// changed here currentNotificationNo insted of REQUEST_CODE_STOP
pendingIntent5 = PendingIntent.getService(getApplicationContext(),
currentNotificationNo, intent5, PendingIntent.FLAG_UPDATE_CURRENT);// changed here currentNotificationNo insted of REQUEST_CODE_STOP
mRemoteViews1.setTextViewText(R.id.playertitle,
MusicList.CurrentNotificationEntity.scrape_title);
mRemoteViews1
.setTextViewText(R.id.playerapaer, Base
.getNewsPaperName(Base.sharedPref.getString(
MusicList.CurrentNotificationEntity.newspaperID,
"Palpal")));
mRemoteViews1.setOnClickPendingIntent(R.id.forward, pendingIntent2);
mRemoteViews1.setOnClickPendingIntent(R.id.backword, pendingIntent3);
mRemoteViews1.setOnClickPendingIntent(R.id.playertitle, contentIntent);
mRemoteViews1.setOnClickPendingIntent(R.id.playerapaer, contentIntent);
mRemoteViews1.setOnClickPendingIntent(R.id.playerimage, contentIntent);
mRemoteViews1.setOnClickPendingIntent(R.id.playpush, pendingIntent);
mRemoteViews1.setOnClickPendingIntent(R.id.close, pendingIntent1);
Notification mNotification1 = new NotificationCompat.Builder(
getApplicationContext())
.setSmallIcon(R.drawable.ic_launcher)
.setWhen(System.currentTimeMillis())
.setPriority(Notification.PRIORITY_HIGH)
.setDeleteIntent(pendingIntent1)
.setAutoCancel(true)
.setContent(mRemoteViews1).setOngoing(false).build();
mNotificationManager.notify(currentNotificationNo, mNotification1); // changed here currentNotificationNo insted of Base.currentNotificationNo
}
这篇关于安卓:从具有远程视窗多个通知更新的具体通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!