안드로이드 app 실행시에 notification과 실행중 리스트에 보여주기
안드로이드 app을 실행할때 notification에서 실행 icon을 보여주고 실행중 리스트에 해당app의 상태와 text를 보여주는 코드
Service에 아래처럼 코드를 추가하고, onStartCommand()에서 showNotification()를 호출해주면 된다.
/**
* Shows the notification message and icon in the notification bar.
*/
private void showNotification() {
int myID = 1234;
//The intent to launch when the user clicks the expanded notification
Intent intent = new Intent(this, TravelLogger_MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent pendIntent = PendingIntent.getActivity(this, 0, intent, 0);
Notification notice = new Notification(R.drawable.map_96, Notfication_Ticker_String, System.currentTimeMillis());
notice.setLatestEventInfo(this, Notfication_Title_String, Notfication_Content_String, pendIntent);
notice.flags |= Notification.FLAG_NO_CLEAR;
startForeground(myID, notice);
Log.d(tag, "showNotification!! ");
}
private void stopNotification() {
Log.d(tag, "stopNotification!! ");
stopForeground(true);
}