2017-07-13 4 views

答えて

0

次のコードを追加することができます

public void createNotification() { 
     // Prepare intent which is triggered if the 
     // notification is selected 
     Intent intent = new Intent(this, NotificationReceiverActivity.class); 
     PendingIntent pIntent = PendingIntent.getActivity(this, (int) System.currentTimeMillis(), intent, 0); 

     // Build notification 
     // Actions are just fake 
     Notification noti = new Notification.Builder(this) 
       .setContentTitle("New mail from " + "[email protected]") 
       .setContentText("Subject").setSmallIcon(R.drawable.icon) 
       .setContentIntent(pIntent) 
       .addAction(R.drawable.delete, "Delete", pIntent) 
       .addAction(R.drawable.reply, "reply", pIntent) 
       .build(); 
     NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); 
     // hide the notification after its selected 
     noti.flags |= Notification.FLAG_AUTO_CANCEL; 

     notificationManager.notify(0, noti); 

    } 
+0

このaddActionメソッドは、アンドロイド22以上で使用できますが、これを古いバージョンでどのように処理できますか? @Avinash –

+0

通知の代わりにNotificationCompat.Builderを試すことができます – Avinash

関連する問題