[JAVA] Add Button in Notification
2021. 2. 20. 18:36ㆍProgramming/Android
Notification에 Button을 Add 하는 방법
1. Notifcation을 눌렀을때 일반적으로 반응할 Intent 선언
2. Notification에서 Button을 눌렀을떄 사용할 Intent를 선언
3. Notification에서 addAction을 추가 (Notifcation EXIT 기능 Action)
createNotificationChannel();
Intent notificationIntent = new Intent(this, MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this,
0, notificationIntent, 0);
//end option
Intent notificationcancleIntent = new Intent(this, MainActivity.class);
//stop userIntent input
notificationcancleIntent.setAction("Stop");
PendingIntent canclependingIntent = PendingIntent.getActivity(this,-99,notificationcancleIntent,PendingIntent.FLAG_UPDATE_CURRENT);
Notification notification = new NotificationCompat.Builder(this, TAG)
.setContentTitle("Foreground Service")
.setContentText(input)
.setSmallIcon(R.drawable.ic_launcher_foreground)
.setContentIntent(pendingIntent)
.setStyle(new NotificationCompat.BigTextStyle().bigText("Foreground Service App"))
.addAction(R.drawable.ic_launcher_foreground,"EXIT", canclependingIntent)
.setAutoCancel(true)
.build();
FULL Code
github.com/Bsoyoung/fg_SMSReceiver/tree/a18f58a904847d7a55b4c9db5a1676fb5891ea6e
Bsoyoung/fg_SMSReceiver
initial commit(foreground service). Contribute to Bsoyoung/fg_SMSReceiver development by creating an account on GitHub.
github.com
'Programming > Android' 카테고리의 다른 글
갤럭시 워치4 버스 어플 만들기 #2 Custom Listview 만들기 (0) | 2022.04.30 |
---|---|
갤럭시 워치4 버스 어플 만들기 #1 환경세팅 (0) | 2022.04.03 |
[JAVA] Foreground Service, send Intent object and thread (0) | 2021.02.20 |
Android Studio Setting (1) | 2021.02.20 |
[JAVA] Foreground Service & SMS Broadcast Example (0) | 2021.02.19 |