カスタム通知があります:
Intent myIntent = new Intent(this, MainActivity.class);
PendingIntent myPendingIntent = PendingIntent.getActivity(this, 0, myIntent, 0);
// build notification
// the addAction re-use the same myIntent to keep the example short
Notification myNotification = new Notification.Builder(this)
.setContentTitle("My App")
.setContentText("Service is not running")
.setSmallIcon(R.drawable.ic_launcher)
.setContentIntent(myPendingIntent)
.setAutoCancel(true)
.addAction(R.drawable.ic_action_mic, "Start Service", myPendingIntent).build();
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notificationManager.notify(0, myNotification);
によって生成されたボタンのどこに onClickListener を配置すればよいかを単純に尋ねています.addAction()
。