전경 서비스를 사용하는 응용 프로그램에서 작업하고 있습니다. 이 목적을 위해 서비스의 onStartCommand 콜백 내부에서 startForeground(id,Notification)
을 호출합니다.Android : 전경 시작 알림이 제대로 표시되지 않음
알림 빌더를 사용하여 알림을 작성하지만 startForeground에 전달할 때 시세 텍스트 만 설정하면 다른 모든 것은 기본값으로 바뀝니다. 즉 제목에 "설정되어있는 동안 실행 중입니다. "온라인 상태입니다."
또한 notification.Builder에서 setText 및 setInfo 메서드를 사용하여 설정 한 항목은 대신 "touch for more information (더 많은 정보를 얻으려면 또는 응용 프로그램을 중지하려면")과 같은 기본 텍스트가 대신 표시됩니다.
여기에 관련 코드가 있습니다.
서비스 :
private final int NOTIFICATION_ID=1;
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Toast.makeText(this,"EDI: Core service Started" , Toast.LENGTH_LONG).show();
startForeground(NOTIFICATION_ID, CoreServiceNotification.getNotification(this, "EDI is online", "Online","Online and running","EDI just started"));
return super.onStartCommand(intent, flags, startId);
}
CoreServiceNotification :
public class CoreServiceNotification {
public static Notification getNotification(Context context,String title,String text,String info,String tickerText){
Notification.Builder notificationBuilder= new Notification.Builder(context);
notificationBuilder.setContentTitle(title);
notificationBuilder.setContentText(text);
notificationBuilder.setContentInfo(info);
notificationBuilder.setTicker(tickerText);
notificationBuilder.setLights(0x00ffff00, 1000, 0);
return notificationBuilder.build();
}
}
결과 : 나는 당신이 알림을 만들 때 먼저 smallIcon을 설정하는 것이 필요하다고 생각
, Cousera 안드로이드 클래스에서 다른 간단한 예입니다, 당신은 notificationManager.notify'등을 추가해야 다음 개체'("1", notificationBuilder); ' –
아니요, 서비스의 StartForeground 메소드에 알림 객체를 전달할 때 여기 메서드 참조 [link] (http://developer.android.com/reference/android/app/Service.html) – Allahjane
다음은 무엇입니까? 너의 문제? –