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

startforeground 시에[ 안드로이드 4.3 이후에는 notification이 실행되는데 이것을 cancel하면 없어진다고 하는데 안되네요

0 추천
service.java

 @SuppressWarnings("deprecation")
 @Override
 public int onStartCommand(Intent intent, int flags, int startId) {
  Log.i(TAG, " +++ onStartCommand Service +++");
 
  startForeground(startId,new Notification());
  
  NotificationManager nm = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
        Notification notification;
        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB){
            notification = new Notification.Builder(getApplicationContext())
                    .setContentTitle("")
                    .setContentText("")
                    .build();
 
        }else{
            notification = new Notification(0, "", System.currentTimeMillis());
            notification.setLatestEventInfo(getApplicationContext(), "", "", null);
        }
        nm.notify(startId, notification);
        nm.cancel(startId);
       
        return super.onStartCommand(intent, flags, startId);
 }

 

cancel이 될때 있고 안될때 있고, 휴대폰마다 적용될때 있고 안될때가 있던데

어떻게 수정해야하나요?
쿠쿠부다스 (6,470 포인트) 님이 2015년 12월 29일 질문

1개의 답변

0 추천

4.xx 버전 이상인 경우에는 setForeGround 하면 null 을 집어넣어두 빈것이 나오고 

위의 버전 미만인 경우 null 을 집어넣으면 foreground 인데도 없는 것처럼 나왔습니다. 

몇버전인지 정확히 기억은 안나는데...아래 링크 보시면..

아래 코드와 같이 쓰면 안보이게하면서 가능하다고 하지만 킷캣부터는 안된다고 합니다.

http://stackoverflow.com/questions/10962418/startforeground-without-showing-notification

 Notification note = new Notification( 0, null, System.currentTimeMillis() );
    note.flags |= Notification.FLAG_NO_CLEAR;
    startForeground( 42, note );
라쎄린드 (25,460 포인트) 님이 2015년 12월 29일 답변
...