0

私のアプリケーションにダウンロード通知があります。 addAction()メソッドを呼び出してNotificationCompat.Builderに「キャンセル」ボタンを追加しました。しかし、Android Oデバイスではボタンが動作しません。 「キャンセル」ボタンを押すと何も起こりません。しかし、ボタンが PendingIntentがAndroid Oで動作していません

Example Screenshot


O.

アンドロイド<に取り組んで私の Notification

NotificationCompat.Builder notification = new NotificationCompat.Builder(context, channelId) 
      .setContentTitle(title) 
      .setSmallIcon(R.drawable.network_download) 
      .setContentText(contentText) 
      .setOngoing(true) 
      .setContentIntent(null) 
      .addExtras(idBundle) 
      .addAction(R.drawable.cancel, context.getString(R.string.cancel), getCancelPendingIntent(context, id)) 
      .setProgress(100, 30, true); 

マイPendingIntent

また
private PendingIntent getCancelPendingIntent(Context context, int id){ 
    return PendingIntent.getBroadcast(
      context, id, new Intent("CANCEL_DOWNLOAD").putExtra("id", id), PendingIntent.FLAG_UPDATE_CURRENT); 
} 

I NotificationReceiverあります

ファイルで

は私が持っている:

<receiver 
     android:name="eu.warble.pjapp.util.NotificationsManager$NotificationReceiver" 
     android:exported="false"> 
     <intent-filter> 
      <action android:name="CANCEL_DOWNLOAD" /> 
     </intent-filter> 
</receiver> 

答えて

3

決して使用暗黙的Intentを明示Intentがどうなるとき。 Android Oは、暗示的に登録された受信者からのIntentブロードキャストの受信を禁止することによって、これを強制するのを助けます。

ステップ#1:あなたの<receiver>から<intent-filter>を取り外します(また、それは、デフォルト値であるとして、あなたは、android:exported="false"を取り除くことができることを意味する)

ステップ#2:new Intent(context, NotificationReceiver.class).putExtra("id", id)

new Intent("CANCEL_DOWNLOAD").putExtra("id", id)を交換してください
関連する問題