我正在尝试使用超过3个意图操作设置状态栏通知,但我可以获得的最大意图操作仅为3:
.addAction(R.drawable.btn_previous, "Prev", pendingIntent_Prev_Song)
.addAction(R.drawable.btn_next, "Next", pendingIntent_Next_Song)
.addAction(R.drawable.ic_launcher, "To App", BackToApp_PendingIntent)
我添加了多少意图操作并不重要,它仍然只在状态栏中显示3。 我知道OnGoing通知可能是我的解决方案,但我无法在不重写整个代码的情况下找到方法。
有人能帮助我吗?
谢谢,谢谢
这是我的代码:
mediaPlayer.setWakeMode(getApplicationContext(),PowerManager.PARTIAL_WAKE_LOCK);
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
NotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
//Back to App Pending Intent
Intent Notification_Intent = new Intent(this, MusicPlayerActivity.class);
BackToApp_PendingIntent = PendingIntent.getActivity(this, 0, Notification_Intent, 0);
//set up notification actions
Intent Prev_Song = new Intent(PREV_SONG);
pendingIntent_Prev_Song = PendingIntent.getBroadcast(this, 0, Prev_Song, 0);
Intent Next_Song = new Intent(NEXT_SONG);
pendingIntent_Next_Song = PendingIntent.getBroadcast(this, 0, Next_Song, 0);
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(PREV_SONG);
intentFilter.addAction(NEXT_SONG);
.....
....
public void DisplayMusicStatusBar() {
StatusBarNotification = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.play_button)
// .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.btn_play))
.addAction(R.drawable.btn_previous, "Prev", pendingIntent_Prev_Song)
.addAction(R.drawable.btn_next, "Next", pendingIntent_Next_Song)
.addAction(R.drawable.ic_launcher, "To App", BackToApp_PendingIntent)
.setContentText(SongsList.get(SongIndex).get("songTitle"))
.setWhen(System.currentTimeMillis())
// .setDefaults(Notification.DEFAULT_SOUND)
.setAutoCancel(false)
.setContent(notificationView).build();
NotificationManager.notify(MUSIC_STATUSBAR_ID, StatusBarNotification);
}
答案 0 :(得分:2)
private static void generateNotification(Context context, String message,
String keys, String msgId, String branchId) {
int icon = R.drawable.ic_launcher;
long when = System.currentTimeMillis();
NotificationCompat.Builder nBuilder;
Uri alarmSound = RingtoneManager
.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
nBuilder = new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("Smart Share - " + keys)
.setLights(Color.BLUE, 500, 500).setContentText(message)
.setAutoCancel(true).setTicker("Notification from smartshare")
.setVibrate(new long[] { 100, 250, 100, 250, 100, 250 })
.setSound(alarmSound);
String consumerid = null;
Integer position = null;
Intent resultIntent = null;
if (consumerid != null) {
if (msgId != null && !msgId.equalsIgnoreCase("")) {
if (key != null && key.equalsIgnoreCase("Yo! Matter")) {
ViewYoDataBase db_yo = new ViewYoDataBase(context);
position = db_yo.getPosition(msgId);
if (position != null) {
resultIntent = new Intent(context,
YoDetailActivity.class);
resultIntent.putExtra("id", Integer.parseInt(msgId));
resultIntent.putExtra("position", position);
resultIntent.putExtra("notRefresh", "notRefresh");
} else {
resultIntent = new Intent(context,
FragmentChangeActivity.class);
resultIntent.putExtra(key, key);
}
} else if (key != null && key.equalsIgnoreCase("Message")) {
resultIntent = new Intent(context,
FragmentChangeActivity.class);
resultIntent.putExtra(key, key);
}.
。 。 。 。
} else {
resultIntent = new Intent(context, FragmentChangeActivity.class);
resultIntent.putExtra(key, key);
}
} else {
resultIntent = new Intent(context, MainLoginSignUpActivity.class);
}
PendingIntent resultPendingIntent = PendingIntent.getActivity(context,
notify_no, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT);
if (notify_no < 9) {
notify_no = notify_no + 1;
} else {
notify_no = 0;
}
nBuilder.setContentIntent(resultPendingIntent);
NotificationManager nNotifyMgr = (NotificationManager) context
.getSystemService(context.NOTIFICATION_SERVICE);
nNotifyMgr.notify(notify_no + 2, nBuilder.build());
}