每天Android重复通知

问题描述 投票:0回答:2

我想每天重复我的通知,我已经做了这个代码,没有错误,但它不会每天重复我的通知......问题出在哪里?

NotificationCompat.Builder mBuilder = (android.support.v7.app.NotificationCompat.Builder) new NotificationCompat.Builder(this)
        .setSmallIcon(R.drawable.tick)
        .setWhen(Calendar.DAY_OF_WEEK)
        .setContentTitle("My notification")
        .setContentText("Hello World!");


Intent notificationIntent = new Intent(this, MainActivity.class);

PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent,
        PendingIntent.FLAG_UPDATE_CURRENT);

mBuilder.setContentIntent(contentIntent);


NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
manager.notify(0, mBuilder.build());
android notifications
2个回答
1
投票

要做到这一点,你应该使用AlarmManager。以下链接将为您提供帮助。

Android Fundamentals: Scheduling Recurring Tasks

Repeat Alarm Example In Android Using AlarmManager


0
投票

系统杀死了这个过程。你可以采取措施让它保持活力

© www.soinside.com 2019 - 2024. All rights reserved.