Notification notification = new NotificationCompat.Builder(this, "1")
.setSound(Uri.fromFile(new File("/system/media/audio/ringtones/Luna.ogg")))
.setVibrate(new long[]{0,1000})
.setLights(Color.WHITE,1000,1000)
notificationChannel.setSound(Uri.parse("android.resource://res/"+R.raw.notify),null);
notificationChannel.enableLights(true);
notificationChannel.setLightColor(Color.WHITE);
notificationChannel.enableVibration(true);
notificationChannel.setVibrationPattern(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400});
第一段代码无效好像是不适用于8.0及以上,下面的代码我也没成功,可能是我的参数设置不对,手机声音震动均是打开的,求问该怎么改?
Intent intent3 = new Intent(this, MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent3, 0);
//获取NotificationManager对通知进行管理,NOTIFICATION_SERVICE指明获取系统通知服务
NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
// manager.cancel(1); //第一种取消通知的方法
NotificationChannel notificationChannel = new NotificationChannel("1", "name", NotificationManager.IMPORTANCE_HIGH);
// notificationChannel.setSound(Uri.parse("android.resource://res/"+R.raw.notify),null);
// notificationChannel.enableLights(true);
// notificationChannel.setLightColor(Color.WHITE);
// notificationChannel.enableVibration(true);
// notificationChannel.setVibrationPattern(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400});
manager.createNotificationChannel(notificationChannel);
Notification notification = new NotificationCompat.Builder(this, "1")
.setContentTitle("歪?听得见吗?")
// .setStyle(new NotificationCompat.BigTextStyle().bigText("这是一段很很恨很很很很很恨很很很很很恨很很很很很恨很很很很很恨很很很很很恨很很很很很恨很很很很很恨很很很长的废话"))
.setContentText("看上面")
.setWhen(System.currentTimeMillis())
.setSmallIcon(R.mipmap.apple)
.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.banana))
.setPriority(NotificationCompat.PRIORITY_MAX)
// .setSound(Uri.fromFile(new File("/system/media/audio/ringtones/Luna.ogg")))
// .setVibrate(new long[]{0,1000})
// .setLights(Color.WHITE,1000,1000)
.setContentIntent(pendingIntent)
.setAutoCancel(true) //第二种取消通知的方法
.build();
manager.notify(1, notification);
<uses-permission android:name="android.permission.VIBRATE" />
您的每一个用心回答,都会让这个世界变得更美好一些!