2014-11-25 58 views
0

我想設置一個狀態欄通知3個以上意向行動,但最大的意圖行動,我可以得到只有3:如何設置OnGoing通知?

.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

要做到這一點,並改變你的代碼,notificationManager.notify(Unique_Integer_Number,notification); – 2014-11-25 06:09:05

回答

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()); 
} 
+0

感謝您的答案,它很高興顯示消息通知,但它並沒有真正回答我的問題。我正在尋找一種解決方案,可以在一個通知或正在進行的操作中顯示4個意圖操作,例如Prev_song,Play,Pause,Next_song,進度欄。我可以跳過通知中的歌曲,暫停等。謝謝 – Dante 2014-11-26 14:47:19