안드로이드 4.3이후에는 startForeground를 사용할시 notification이 뜨는데
카톡도 동이라게사용하고 있다고 하던데 카톡은 notification이 뜨지 않습니다.
@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);
}
이 방법을 통해서 notification이 cancel이 되기는 한데 가끔씩 cancel이 안 될때가 있습니다.
onDestory에서도
NotificationManager nm = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
nm.cancelall();
해보았지만 가끔씩 cancel되지 않습니다.
혹시 이 문제를 해결하는 방안을 아시는 분은 제발 알려주시면 감사하겠습니다.
부탁드립니다.