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 ++;
}
"작동하지 않음"을 정의하십시오. 그냥 아무 것도하지 않거나 어떤 종류의 오류가 있습니까? 오류 메시지가 나타나면 logcat을 게시하여보다 쉽게 도움을 받으십시오. – codeMagic
'PendingIntent.getActivity (context, 0, notificationIntent, 0);'유효한 값이 아닌'flags' 매개 변수에 0을 사용하고 있습니다. 'PendingIntent'' FLAG_' 상수 중 하나를 사용하십시오. – Squonk
@codeMagic 자동 오류입니다. 모든 것이 잘되나 알림은 실행되지 않습니다. 그냥. – Chema