2013-02-15 2 views
0

주 활동에서 알림을 만들려고합니다. 여기 생성자 Notification (int, String, long)이 정의되지 않았습니다.

내 코드입니다 -

public class Notification extends Activity{ 

private static final int NOTIFY_ME_ID=1987; 
private int count=0; 
private NotificationManager mgr=null; 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 

    super.onCreate(savedInstanceState); 

    mgr=(NotificationManager)getSystemService(NOTIFICATION_SERVICE); 

    notifyMe(); 

    } 


public void notifyMe(){ 

Notification notification = new Notification(R.drawable.icon, 
     "Notification text that will be shown on status bar.", 
     System.currentTimeMillis()); 

// The PendingIntent will launch activity if the user selects this 
// notification 
PendingIntent contentIntent = PendingIntent.getActivity(Notification.this, 
     0, new Intent(Notification.this, MainActivity.class), 0); 
notification.setLatestEventInfo(Notification.this, "Content Title", "Content text", 
     contentIntent); 
mgr.notify(NOTIFICATION_ID, notification); 

} 

그러나 나는 다음과 같은 오류 얻을 : 생성자 알림 (INT는, 문자열, 길이가) 정의되지

나는 오류 라인은 다음과 같습니다

답변

1

Android Notification의 생성자에는 아무런 문제가 없습니다.이 문제는 귀하의 활동 이름에도 있으며 Notification입니다. 문제를 해결하려면 다른 이름으로 변경해야합니다.

활동 이름을 변경하는 대신 패키지를 포함하여 알림을 사용하는 시스템을 지울 수 있습니다. 사용자 시스템 32가 제공하는 this solution을 참조하십시오.

0

Notification.Builder을 사용하면 here과 같이 알림을 만들 수 있습니다.

+0

에 그 활동의 이름을 변경하는 것이 좋습니다? 이 코드에서 내가 뭘하고 있는지 알고 싶습니다. –

+0

예 이전 생성자도 API 9 이상에서만 작동해야합니다. 어떤 API를 컴파일하고 있습니까? –

+0

API 레벨 8 - Froyo –

1
android.app.Notification notification 
       = new android.app.Notification(icon, tickerText, when); 

나는 나이가 안드로이드 버전으로 작동합니까 NotificationActivity

관련 문제