마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

PendingIntent.getService가 안 되는 같은데 조언좀 부탁드립니다.

0 추천
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;
 }

}
쿠쿠부다스 (6,470 포인트) 님이 2016년 1월 18일 질문

답변 달기

· 글에 소스 코드 보기 좋게 넣는 법
· 질문에 대해 추가적인 질문이나 의견이 있으면 답변이 아니라 댓글로 달아주시기 바랍니다.
표시할 이름 (옵션):
개인정보: 당신의 이메일은 이 알림을 보내는데만 사용됩니다.
스팸 차단 검사:
스팸 검사를 다시 받지 않으려면 로그인하거나 혹은 가입 하세요.
...