为什么Android的警报管理器不起作用?

时间:2019-09-22 07:54:12

标签: android notifications alarmmanager

我已经编码为使用警报管理器设置警报,但是无法正常工作。

在我的主要活动中:

            Calendar calendar = Calendar.getInstance();
            calendar.set(Calendar.HOUR_OF_DAY, 10);
            calendar.set(Calendar.MINUTE, 45);
            calendar.set(Calendar.SECOND, 0);

            Intent notificationmassage = new Intent(c, Broadcast_NotificationMassage.class);

            PendingIntent pi = PendingIntent.getService(c, 1253, notificationmassage, PendingIntent.FLAG_UPDATE_CURRENT);
            AlarmManager am = (AlarmManager) c.getSystemService(c.ALARM_SERVICE);
            am.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pi);

我的收件人代码:

    public class Broadcast_NotificationMassage extends BroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {



        Intent contentIntent = new Intent(context, Activity_Notification.class);
        PendingIntent pi = PendingIntent.getActivity(context, 0, contentIntent, PendingIntent.FLAG_UPDATE_CURRENT);

        NotificationCompat.Builder mBuilder =
                new NotificationCompat.Builder(context)
                        .setSmallIcon(R.drawable.ic_launcher)
                        .setContentTitle(msg)
                        .setContentText(msg);
        mBuilder.setContentIntent(pi);

            mBuilder.setDefaults(Notification.DEFAULT_SOUND);


        mBuilder.setAutoCancel(true);
        NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        mNotificationManager.notify(1, mBuilder.build());
    }


}

清单中

 <receiver android:name="ir.newagegroup.modir.Broadcast_NotificationMassage">
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED"></action>
        </intent-filter>
    </receiver>

我希望在关闭应用程序或重新启动设备时发生这种情况,但是即使打开应用程序也无法正常工作。为什么?

0 个答案:

没有答案