0

Я хочу, чтобы добавить кнопку действия для уведомления напоминания так, всякий раз, когда пользователь нажимает на такое уведомление, которое требуется пользователю файл макета ..Добавление кнопки действий для андроида уведомления

Я знаю, как добавить кнопки действий в целом но как я могу добавить кнопку действия по уведомлению в этом коде ..

нужна помощь .. спасибо заранее ..

кодекс Здесь ..

public void onReceive(Context context, Intent intent) 
     { 
      MediaPlayer mPlayer = MediaPlayer.create(context, R.raw.alert); 
      mPlayer.start(); 
      mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); 
      CharSequence from = intent.getStringExtra("Name"); 
      CharSequence message = intent.getStringExtra("Description"); 
      PendingIntent contentIntent = PendingIntent.getActivity(context, 0, new Intent(), 0); 
      notification = new Notification(R.drawable.alert, "Notification", System.currentTimeMillis()); 
      notification.setLatestEventInfo(context, from, message, contentIntent); 
      mNotificationManager.notify(Integer.parseInt(intent.getExtras().get("NotifyCount").toString()), notification); 
      Toast.makeText(context, "New Notification Received", Toast.LENGTH_LONG).show(); 
     } 
+0

Это означает, что вы кнопка в панели уведомлений нужна? –

+0

да, мне нужно добавить кнопку в уведомлении – SparrOw

+0

Jiya, мне кажется, вам нужно создать пользовательскую кнопку –

ответ

1
public void onReceive(Context context, Intent intent) 
    { 
     MediaPlayer mPlayer = MediaPlayer.create(context, R.raw.alert); 
     mPlayer.start(); 
     mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); 
     CharSequence from = intent.getStringExtra("Name"); 
     CharSequence message = intent.getStringExtra("Description"); 
     PendingIntent contentIntent =  PendingIntent.getActivity(context, 0, new Intent(), 0); 
     notification = new Notification(R.drawable.alert, "Notification", System.currentTimeMillis()); 
     notification.addAction(R.mipmap.yes, "Acion_Name", contentIntent); 
     mNotificationManager.notify(Integer.parseInt(intent.getExtras().get("NotifyCount").toString()), notification); 
     Toast.makeText(context, "New Notification Received", Toast.LENGTH_LONG).show(); 
    } 

Так что вам просто нужно добавить .addAction Эту строку коды, где где вы называете Pending Намерения:

notification.addAction(R.mipmap.yes, "Acion_Name", contentIntent); 
Смежные вопросы