2012-12-14 5 views
0

Android에서 로컬 알림을 예약하는 간단한 기능을 만들려고하지만 작동하지 않습니다. 내가 놓친 게 있니? 나는. 이자형. 매니페스트에있는 허락이나 뭐 그런 거요? 나는 안드로이드 프로그래밍 꽤 초보자입니다.Android 알림 일정 기능에 문제가 있습니까?

static int notificationId = 0; 

public void scheduleLocalNotification(String text, int seconds) 
{ 
    Context context = getApplicationContext(); 
    long when = System.currentTimeMillis() + seconds * 1000; 
    NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); 

    Intent notificationIntent = new Intent(context, MyApp.class); 

    // set intent so it does not start a new activity 
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP 
      | Intent.FLAG_ACTIVITY_SINGLE_TOP); 
    PendingIntent intent = PendingIntent.getActivity(context, 0, 
      notificationIntent, 0); 
    Notification notification = new Notification(); 
    notification.setLatestEventInfo(context, "My application", text, intent); 
    notification.flags |= Notification.FLAG_AUTO_CANCEL; 
    notification.when = when; 
    notificationManager.notify(notificationId, notification); 
    notificationId ++; 

} 
+0

"작동하지 않음"을 정의하십시오. 그냥 아무 것도하지 않거나 어떤 종류의 오류가 있습니까? 오류 메시지가 나타나면 logcat을 게시하여보다 쉽게 ​​도움을 받으십시오. – codeMagic

+0

'PendingIntent.getActivity (context, 0, notificationIntent, 0);'유효한 값이 아닌'flags' 매개 변수에 0을 사용하고 있습니다. 'PendingIntent'' FLAG_' 상수 중 하나를 사용하십시오. – Squonk

+0

@codeMagic 자동 오류입니다. 모든 것이 잘되나 알림은 실행되지 않습니다. 그냥. – Chema

답변

1

난 당신이 그래서 그냥 항목 활동 등 내가 그것을 발견

+0

가지고 있습니다. MyApp "android : label ="@ string/app_name ">'엔트리 ' – Chema

0

<activity 
     android:name=".your activity name" 
     /> 

및 실행 프로그램 아래에 주어진 안드로이드 매니페스트 파일에서 새로운 활동의 항목을 잊지 생각합니다. 문제는 아이콘 리소스를 알림 생성자에 전달하지 않는다는 것입니다.

notification = new Notification(R.drawable.icon, text, when); 
관련 문제