2017-09-07 3 views
5

Android Oのサポートを追加して以来、Oを実行しているAndroidデバイスは、アプリのメディアコントロールの通知が更新されるたびに(メタデータまたは再生状態の変更)アラートを受信します。このアラートを無効にする方法を探しています。メディアスタイルの通知には適用されないからです。メディアコントロールの通知がAndroid Oのアラートを発する

MediaDescriptionCompat description = metadata.getDescription(); 
String artistName = metadata.getString(MediaMetadataCompat.METADATA_KEY_ARTIST); 
String albumName = metadata.getString(MediaMetadataCompat.METADATA_KEY_ALBUM); 
Bitmap largeIcon = BitmapFactory.decodeResource(playbackService.getResources(), 
     R.drawable.vector_global_defaultsong); 

NotificationCompat.Builder notificationBuilder = new NotificationCompat 
     .Builder(playbackService, NotificationHelper.CHANNEL_MEDIA_CONTROLS) 
     .setColor(ContextCompat.getColor(playbackService, R.color.colorAccent)) 
     .setSmallIcon(R.drawable.logo_light_filled) 
     .setContentTitle(description.getTitle()) 
     .setContentText(playbackService.getString(R.string.song_list_subtitle_format, 
       artistName, albumName)) 
     .setContentIntent(createContentIntent()) 
     .setDeleteIntent(MediaButtonReceiver.buildMediaButtonPendingIntent(playbackService, 
       PlaybackStateCompat.ACTION_STOP)) 
     .setVisibility(NotificationCompat.VISIBILITY_PUBLIC) 
     .setOngoing(playbackState.getState() == PlaybackStateCompat.STATE_PLAYING) 
     .setLargeIcon(largeIcon); 

notificationBuilder.setStyle(new android.support.v4.media.app.NotificationCompat.MediaStyle() 
     // show previous, play/pause, and next in compact view 
     .setShowActionsInCompactView(addActions(notificationBuilder)) 
     .setMediaSession(sessionToken)); 
showNotification(notificationBuilder.build()); 

:ここ

は、私はメディアコントロール通知を作成するために使用するコードです。 。 。ここで

private void showNotification(final Notification notification) { 
    if (!started) { 
     mediaController.registerCallback(mediaControllerCallback); 
     playbackService.startForeground(NOTIFICATION_ID, notification); 
     started = true; 
    } else { 
     notificationManager.notify(NOTIFICATION_ID, notification); 
    } 

    if (playbackState.getState() == PlaybackStateCompat.STATE_PAUSED) { 
     playbackService.stopForeground(false); 
    } 
} 

私は通知チャネルを作成するために使用するコードです:

public static final String CHANNEL_MEDIA_CONTROLS = "media_controls"; 

public static void createNotificationChannels(Context context) { 
    if (android.os.Build.VERSION.SDK_INT >= 26) { 
     NotificationChannel mediaControlsChannel = new NotificationChannel(CHANNEL_MEDIA_CONTROLS, 
       context.getString(R.string.notification_channel_media_controls), 
       NotificationManager.IMPORTANCE_HIGH); 
     mediaControlsChannel.setShowBadge(false); 
     getNotificationManager(context).createNotificationChannel(mediaControlsChannel); 
    } 
} 

を更新:通知チャネル上falseshowBadgeを設定すると、何もする表示されません。メディアコントロールの通知が表示されても、アプリアイコンにバッジが表示されます。したがって、設定した通知チャネルの属性が適用されていないように見えます。

答えて

9

Migrating MediaStyle notifications to Android Oには、IMPORTANCE_LOWを使用する必要があります。これにはサウンドが含まれていません。IMPORTANCE_HIGHチャネルにはサウンドが関連付けられています。

Androidは既にトレイ内の通知の順序が変更されているため、Androidの以前のバージョンと同じように、重要度を高くする必要はありません。

+1

Hey @ianhanniballake。応答していただきありがとうございます。昨夜、IMPORTANCE_LOWを含め、さまざまな重要度レベルをテストしましたが、無駄です。 Oreoを実行しているPixelにはまだ警告音が聞こえます。 – Ryan

+5

通知チャネルは、作成後は編集できません(ユーザー以外)。アプリ内のデータを消去してチャンネルを完全に削除してみてください。 – ianhanniballake

+0

ああ、意味がある。アプリのデータをクリアするのは難しかった。どうもありがとう! – Ryan

関連する問題