Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/224.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Android通知生成器声音不运行_Java_Android - Fatal编程技术网

Java Android通知生成器声音不运行

Java Android通知生成器声音不运行,java,android,Java,Android,uri在调试时有一个值,但set.sound不起作用,也不运行声音程序 private void notification(){ uri = intent.getData(); int notifictionId = 1; Notification.Builder Builder = new Notification.Builder(this) .setSmallIcon(R.drawable.eye_rest) .setLargeIcon(BitmapFactory.deco

uri在调试时有一个值,但set.sound不起作用,也不运行声音程序

private void notification(){
uri = intent.getData();
int notifictionId = 1;
Notification.Builder Builder = new Notification.Builder(this)

    .setSmallIcon(R.drawable.eye_rest)
    .setLargeIcon(BitmapFactory.decodeResource(getResources(),R.drawable.eye_rest))
    .setContentTitle("Eye rest")
    .setContentText("It's time to rest the eyes")
    .setAutoCancel(true)
    .setVibrate(new long[] { 600, 600 })
    .setSound(uri);

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
  String channelId = "YOUR_CHANNEL_ID";
  NotificationChannel channel = new NotificationChannel(channelId,"Channel human readable title",NotificationManager.IMPORTANCE_DEFAULT);
  channel.enableLights(true);
  channel.setLightColor(Color.BLUE);
  channel.setSound(uri,null);
  Builder.setVisibility(Notification.VISIBILITY_PRIVATE);
  notificationManager.createNotificationChannel(channel);
  Builder.setChannelId(channelId);
}
notificationManager.notify(notifictionId, Builder.build());
我通过以下代码从手机铃声列表中选择声音:

    intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
            uri = RingtoneManager.getActualDefaultRingtoneUri(this, RingtoneManager.TYPE_NOTIFICATION | RingtoneManager.TYPE_RINGTONE );
            intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_NOTIFICATION | RingtoneManager.TYPE_RINGTONE);
            intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true);
            intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE,  "Choose a song for notification");
            intent.putExtra(RingtoneManager.EXTRA_RINGTONE_DEFAULT_URI, RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
            startActivity(intent);