In service에서
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
//종료
Intent finishIntent = new Intent(this, NotificaitonService.class);
PendingIntent pfinishIntent = PendingIntent.getService(this, 0, finishIntent, 0);
//나머지 버튼
Intent notiintent = new Intent(this, MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notiintent, 0);
Notification notification = new Notification.Builder(this)
.setSmallIcon(R.drawable.ic_launcher)
.setWhen(System.currentTimeMillis())
.setContentTitle("App bluetooth")
.setContentText("블루투스 실행중")
.setTicker("블루투스 실행중")
.addAction(R.drawable.x, "App Finish", pfinishIntent) //버튼 클릿시
.setContentIntent(pendingIntent) // 앱 실행 버튼
.build();
startForeground(NOTIFICATION_ID, notification);
return Service.START_REDELIVER_INTENT;
}
pendingIntent는 MainActivity가 바로 실행이됩니다.
pfinishIntent는 눌렀을 때 NotificationService.class로 들어가지 않습니다.
어떻게 수정을 해야하는건가요?
NotificationService.java
public class NotificaitonService extends Service{
private static final String TAG = "Notification Service";
@Override
public void onCreate() {
Log.d(TAG, "# Service - onCreate() starts here");
stopSelf();
stopForeground(true);
}
@Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
return null;
}
}