0

Androidでアクション可能な通知を開発しています。Android - 通知バーにアクションを表示できません

void createActionableNotification() { 
    Intent intent = new Intent(this, MainActivity.class); 
    PendingIntent pIntent = PendingIntent.getActivity(this, (int) System.currentTimeMillis(), intent, 0); 

    // Build notification 
    // Actions are just fake 
    Notification noti = new NotificationCompat.Builder(this) 
      .setContentTitle("New mail from " + "[email protected]") 
      .setContentText("Subject").setSmallIcon(R.drawable.moneybag) 
      .setContentIntent(pIntent) 
      .addAction(R.drawable.moneybag, "Call", pIntent) 
      .addAction(R.drawable.moneybag, "More", pIntent) 
      .addAction(R.drawable.moneybag, "And more", pIntent).build(); 
    NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); 
    // hide the notification after its selected 

    noti.flags |= Notification.FLAG_AUTO_CANCEL; 

    notificationManager.notify(0, noti); 
} 

このように、以下の画像を確認してください。 enter image description here

アプリターゲットSDKで走っている、コンパイルSDK APIが最小SDK私はマシュマロデバイスでテスト20 で、24です。しかし、エミュレータでうまく動作します。リスト内の任意継続的なNotification存在があるときにボタンは、このようなメディアプレーヤーのコントロールとして、表示されませんAPIのために働く> = 16

Notification notification = new Notification.Builder(myContext) 
.setContentTitle("New mail from " + "[email protected]") 
      .setContentText("Subject").setSmallIcon(R.drawable.moneybag) 
      .setContentIntent(pIntent) 
      .setPriority(Notification.PRIORITY_MAX) 
      .addAction(R.drawable.moneybag, "Call", pIntent) 
      .addAction(R.drawable.moneybag, "More", pIntent) 
      .addAction(R.drawable.moneybag, "And more", pIntent).build(); 

//The rest of your options 
.build(); 

:エミュレータSDKのバージョンは、これを24 enter image description here

答えて

0

てみています、またはUSB経由でPCに接続されている携帯電話を持っているか、あなたがテキストを編集しているとき...

あなたはこれを回避するためにNotification.PRIORITY_MAXを試す、または回答のためPRIORITY_HIGH

+0

感謝することができます。私はPriorityとSetwhen(0)も試しました。しかし、変化はありません。 @ rafsanahmad007 – Roster

+0

あなたの通知にスタイルを追加しようとしています: '.setStyle(new NotificationCompat.BigTextStyle()。bigText(th_alert))' – rafsanahmad007

+0

これを参照してください:http://stackoverflow.com/questions/ 13720670/implement-expand-and-collapse-notification-android – rafsanahmad007

関連する問題