2014-04-18 6 views
13

전경 서비스를 사용하는 응용 프로그램에서 작업하고 있습니다. 이 목적을 위해 서비스의 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을 설정하는 것이 필요하다고 생각 enter image description here

+0

, Cousera 안드로이드 클래스에서 다른 간단한 예입니다, 당신은 notificationManager.notify'등을 추가해야 다음 개체'("1", notificationBuilder); ' –

+1

아니요, 서비스의 StartForeground 메소드에 알림 객체를 전달할 때 여기 메서드 참조 [link] (http://developer.android.com/reference/android/app/Service.html) – Allahjane

+0

다음은 무엇입니까? 너의 문제? –

답변

21

. 여기

Notification.Builder notificationBuilder= new Notification.Builder(context); 
notificationBuilder.setSmallIcon(R.drawable.yourIcon); 
// then set other staff... 

난 당신이`노 티피 케이션 티피 케이션을 작성하는 것을 잊지 생각 Click here

+2

이 답변은 수락 된 것으로 표시되어야합니다. –

+0

먼저 smallIcon을 설정해도 예외가 발생하지 않도록하는 데 도움이되지 않습니다! – Tano

+0

idk이 내 문제를 어떻게 이길까요? 어쨌든 바구니 감사합니다. –

관련 문제