我有一个本地通知,每天在特定时间重复。我尝试使用一些设备进行测试,但它仅适用于少数设备。请检查下面的代码并说明一些问题。我尝试过三星和 LG 设备。下面是我的 AlarmReceiver public class AlarmReceiver extends BroadcastReceiver {@Overridepublic void onReceive(Context context, Intent intent) { MediaPlayer mediaPlayer = MediaPlayer.create(context, Settings.System.DEFAULT_NOTIFICATION_URI); mediaPlayer.start(); NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); NotificationCompat.Builder builder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.logo) //example for large icon .setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.mipmap.ic_launcher)) .setContentTitle("Hey") .setContentText("Did you read today") .setOngoing(false) .setPriority(NotificationCompat.PRIORITY_DEFAULT) .setAutoCancel(true); Intent i = new Intent(context, VerseActivity.class); PendingIntent pendingIntent = PendingIntent.getActivity( context, 0, i, PendingIntent.FLAG_ONE_SHOT ); // example for blinking LED builder.setLights(0xFFb71c1c, 1000, 2000); builder.setSound(Settings.System.DEFAULT_NOTIFICATION_URI); builder.setContentIntent(pendingIntent); manager.notify(12345, builder.build());}}
添加回答
举报
0/150
提交
取消