android本地推送(退出app后依然可以)
16lz
2021-01-25
1.小米手机无效,MIUI系统似乎改过android底层的一些东西
主要就是用到了AlarmManager,接着在AlarmReceiver实现notification 。 记得在manifest中添加AlarmReceiver即可
AlarmManager alarmManager = (AlarmManager) mContext.getSystemService(ALARM_SERVICE);Intent myIntent = new Intent(mContext, AlarmReceiver.class);myIntent.putExtra("msg", msg);myIntent.putExtra("id", count);// 第二个参数一定不一样 否则重复只会让最后一个起作用System.out.println("yzj id = " + count);PendingIntent pendingIntent = PendingIntent.getBroadcast(mContext, count++, myIntent, 0); alarmManager.set(AlarmManager.RTC, Calendar.getInstance().getTimeInMillis() + time, pendingIntent);
附上github地址:https://github.com/playscforever/TestLocalNotification.git (里面的NotificationService.java是不需要的)
更多相关文章
- Android(安卓)Service的两种启动方式
- someone's android note
- [置顶] Android-->Rxjava与Retrofit2的结合实战
- Android调用系统前置相机拍照
- Android(安卓)SharedPreferences的使用
- Android(安卓)opencv人脸识别
- Android(安卓)完美解决各个版本状态栏设置透明解决办法
- Android音效SoundPool问题:soundpool 1 not retry
- Android中利用HttpURLConnection发送Post请求并添加参数的写法