我有一個本地通知,每天在特定時間重復(fù)。我嘗試使用一些設(shè)備進行測試,但它僅適用于少數(shù)設(shè)備。請檢查下面的代碼并說明一些問題。我嘗試過三星和 LG 設(shè)備。下面是我的 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
提交
取消