Android 警报管理器未显示通知无错误
即使在指定的时间过后,我的闹钟也不会显示通知。 并且不显示错误。这是我的密码。我很困惑,因为没有错误信息,警报也没有出现 我试图找到其他的参考资料,但还是找不到。其他人是否有任何问题导致报警管理器不出现Android 警报管理器未显示通知无错误,android,alarmmanager,Android,Alarmmanager,即使在指定的时间过后,我的闹钟也不会显示通知。 并且不显示错误。这是我的密码。我很困惑,因为没有错误信息,警报也没有出现 我试图找到其他的参考资料,但还是找不到。其他人是否有任何问题导致报警管理器不出现 private void sendNotification(Context context, String title, String desc, int id) { NotificationManager mNotificationManager = (NotificationMan
private void sendNotification(Context context, String title, String desc, int id) {
NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(
Context.NOTIFICATION_SERVICE);
Intent mIntent = new Intent(context, SettingActivity.class);
PendingIntent mPendingIntent = PendingIntent.getActivity(context, id, mIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
Uri uriTone = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.ic_notifications_black_24dp)
.setContentTitle(title)
.setContentText(desc)
.setContentIntent(mPendingIntent)
.setColor(ContextCompat.getColor(context, android.R.color.transparent))
.setVibrate(new long[]{1000, 1000, 1000, 1000, 1000})
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setAutoCancel(true)
.setSound(uriTone);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel mNotificationChannel = new NotificationChannel(
"11001", "NOTIFICATION_CHANNEL_NAME",
NotificationManager.IMPORTANCE_HIGH);
mNotificationChannel.enableLights(true);
mNotificationChannel.setLightColor(Color.YELLOW);
mNotificationChannel.enableVibration(true);
mNotificationChannel.setVibrationPattern(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400});
builder.setChannelId("11001");
mNotificationManager.createNotificationChannel(mNotificationChannel);
}
mNotificationManager.notify(id, builder.build());
}
private static PendingIntent getPendingIntent(Context context) {
Intent mIntent = new Intent(context, DailyAlarm.class);
return PendingIntent.getBroadcast(context, 1001, mIntent, PendingIntent.FLAG_CANCEL_CURRENT);
}
public void setAlarm(Context context) {
cancelAlarm(context);
AlarmManager mAlarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
Calendar mCalendar = Calendar.getInstance();
mCalendar.set(Calendar.HOUR_OF_DAY, 17);
mCalendar.set(Calendar.MINUTE, 35);
mCalendar.set(Calendar.SECOND, 0);
if(Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT && Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
mAlarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP,mCalendar.getTimeInMillis(),AlarmManager.INTERVAL_DAY,getPendingIntent(context));
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
mAlarmManager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP,mCalendar.getTimeInMillis(), getPendingIntent(context));
}
Toast.makeText(context, "Daily Notif ON", Toast.LENGTH_SHORT).show();
}
public void cancelAlarm(Context context) {
AlarmManager mAlarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
mAlarmManager.cancel(getPendingIntent(context));
Toast.makeText(context, "Daily Notif OFF", Toast.LENGTH_SHORT).show();
}
@Override
public void onReceive(Context context, Intent mIntent) {
sendNotification(context, context.getString(R.string.app_name),
context.getString(R.string.daily_reminder), 1001);
}
private void sendNotification(上下文上下文、字符串标题、字符串描述、int id){
NotificationManager mNotificationManager=(NotificationManager)context.getSystemService(
通知服务);
Intent MINENT=新的Intent(上下文,setingActivity.class);
pendingent mpendingent=pendingent.getActivity(上下文、id、minent、,
PendingEvent.FLAG_UPDATE_CURRENT);
Uri uriTone=ringtonemager.getDefaultUri(ringtonemager.TYPE_通知);
NotificationCompat.Builder=新建NotificationCompat.Builder(上下文)
.setSmallIcon(R.drawable.ic\U通知\U黑色\U 24dp)
.setContentTitle(标题)
.setContentText(描述)
.setContentIntent(mpendingContent)
.setColor(ContextCompat.getColor(context,android.R.color.transparent))
.setVibrate(新长[]{1000,1000,1000,1000})
.setPriority(通知兼容优先级高)
.setAutoCancel(真)
.setSound(尿石);
if(Build.VERSION.SDK\u INT>=Build.VERSION\u code.O){
NotificationChannel mNotificationChannel=新建NotificationChannel(
“11001”,“通知渠道名称”,
通知经理(重要性高);
mNotificationChannel.enableLights(真);
mNotificationChannel.setLightColor(Color.YELLOW);
mNotificationChannel.启用振动(真);
mNotificationChannel.setVibrationPattern(新的长[]{100200300400500400300200400});
builder.setChannelId(“11001”);
mNotificationManager.createNotificationChannel(mNotificationChannel);
}
mNotificationManager.notify(id,builder.build());
}
私有静态PendingEvent GetPendingEvent(上下文){
Intent MINENT=新的Intent(上下文,DailyAlarm.class);
返回pendingent.getBroadcast(上下文,1001,minent,pendingent.FLAG_CANCEL_CURRENT);
}
公共无效设置报警(上下文){
取消报警(上下文);
AlarmManager mAlarmManager=(AlarmManager)context.getSystemService(context.ALARM\u服务);
Calendar mCalendar=Calendar.getInstance();
mCalendar.set(日历时间,17天);
mCalendar.set(Calendar.MINUTE,35);
mCalendar.set(Calendar.SECOND,0);
if(Build.VERSION.SDK\u INT>Build.VERSION\u code.KITKAT&&Build.VERSION.SDK\u INT=Build.VERSION\u code.M){
mAlarmManager.setExactAndAllowHileIDLE(AlarmManager.RTC_WAKEUP,mCalendar.getTimeInMillis(),getPendingEvent(上下文));
}
Toast.makeText(上下文,“每日不开”,Toast.LENGTH_SHORT.show();
}
公共无效取消报警(上下文){
AlarmManager mAlarmManager=(AlarmManager)context.getSystemService(context.ALARM\u服务);
mAlarmManager.cancel(getpendingent(context));
Toast.makeText(上下文,“每日不关闭”,Toast.LENGTH_SHORT.show();
}
@凌驾
公共void onReceive(上下文、意图输入){
sendNotification(context,context.getString(R.string.app_name),
getString(R.string.daily_提醒),1001);
}
有一个与您的问题相似或相近的问题,您看到了吗
这里还有一些可能对你有所帮助的提示
有一个与你的问题相似或相近的问题,你看到了吗 这里还有一些可能对你有所帮助的提示
finish,我忘了在清单文件中添加接收者。finish,我忘了在清单文件中添加接收者。