我正在编写通知应用程序。要设置通知,我使用 AlarmManager。
一切似乎都运行良好,不幸的是在华为没有。当用户关闭应用程序通知时(在其他设备上 LG、NEXUS 都运行良好)。
知道如何解决吗?
intent = new Intent(context, AlarmReceiver.class);
sender = PendingIntent.getBroadcast(context, alarmId, intent, 0);
am.set(android.app.AlarmManager.RTC_WAKEUP, timeToAlarm, sender);
编辑
public class AlarmReceiver extends BroadcastReceiver {
private static final String TAG = "AlarmReceiver";
private PowerManager.WakeLock wakeLock;
@Override
public void onReceive(Context context, Intent intent) {
PowerManager pm = (PowerManager) context
.getSystemService(Context.POWER_SERVICE);
wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG);
wakeLock.acquire();
new NotificationUtils(context, null).postNotification(context.getString(R.string.notification_title), context.getString(R.string.notification_message));
unlock();
}
private void unlock() {
if (wakeLock != null)
if (wakeLock.isHeld())
wakeLock.release();
wakeLock = null;
}
}