我使用MediaStyle我的推送通知,這樣我可以顯示當前播放的歌曲的元數據以及包括暫停按鈕。我看到的問題是,即使我已經包含了setShowActionsInCompactView(),我的通知不會自動展開以顯示暫停按鈕。如果我在鎖定屏幕上拉下我的通知,它會展開,然後顯示暫停按鈕。但我希望它顯示按鈕不擴大。是如何顯示的通知MediaStyle通知到放映按鈕在精簡視圖
截圖: http://cl.ly/image/3E2D0m403v1b
如何拉下來就可以了擴大後顯示的通知截圖: http://cl.ly/image/1N1i0G121i2Y
下面是我用來生成通知的代碼片段:
PendingIntent pi = PendingIntent.getActivity(getApplicationContext(), 0, new Intent(getApplicationContext(), MainActivity.class), PendingIntent.FLAG_UPDATE_CURRENT);
Bitmap icon = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
Intent intent = new Intent(BROADCAST_PLAYER_STOP);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, 0);
NotificationCompat.Builder notification = new NotificationCompat.Builder(this)
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
.setContentTitle(getResources().getString(R.string.app_name))
.setTicker(tickerString)
.setContentText(contentString)
.setSmallIcon(R.drawable.ic_notification)
.setLargeIcon(icon)
.addAction(R.drawable.ic_media_pause, "", pendingIntent)
.setContentIntent(pi)
.setStyle(new android.support.v7.app.NotificationCompat.MediaStyle()
.setShowActionsInCompactView(0)
.setMediaSession(mSession.getSessionToken()))
.setPriority(NotificationCompat.PRIORITY_MAX)
.setWhen(0)
.setOngoing(true);
startForeground(NOTIFICATION_ID, notification.build());
您可以包括是你所看到的截圖?而且要清楚的是,您正在API 21+設備上測試此功能嗎? – ianhanniballake
剛更新的問題與截圖。另外,我正在測試運行Android 5.1.1的Galaxy S6。但是我嘗試過的所有模擬器的行爲都是一樣的。 – codeman
也許我最好使用RemoteViews的自定義視圖進行通知? – codeman