自定义铃声设置为默认为什么?

时间:2019-06-12 05:32:15

标签: java android

我使用RecyclerView的每个列表都有自己的声音。我想要当用户单击列表项时将特定声音设置为默认铃声。注意。第二个问题是,我以编程方式设置了自定义铃声,并且正在播放的默认声音都被选择为自定义铃声和默认铃声。

File ringtoneFile = new File("raw/ali.mp3"); //sd-card path/songname.mp3
ContentValues content = new ContentValues();
content.put(MediaStore.MediaColumns.DATA,ringtoneFile.getAbsolutePath());
content.put(MediaStore.MediaColumns.TITLE, "ali");
content.put(MediaStore.MediaColumns.SIZE, 215454);
content.put(MediaStore.MediaColumns.MIME_TYPE, "audio/*");
content.put(MediaStore.Audio.Media.ARTIST, "Madonna");
content.put(MediaStore.Audio.Media.DURATION, 2000);
content.put(MediaStore.Audio.Media.IS_RINGTONE, true);
content.put(MediaStore.Audio.Media.IS_NOTIFICATION, true);
content.put(MediaStore.Audio.Media.IS_ALARM, false);
content.put(MediaStore.Audio.Media.IS_MUSIC, true);

Uri Ringtone1 = Uri.parse("current song fi33le path");
//Insert it into the database
Log.i("TAG", "the absolute path of the file is :"+
       ringtoneFile.getAbsolutePath());
Uri uri = MediaStore.Audio.Media.getContentUriForPath(ringtoneFile.getAbsolutePath());
context.getContentResolver().delete(uri, MediaStore.MediaColumns.DATA + "=\"" + ringtoneFile.getAbsolutePath() + "\"", null);
Uri newUri = context.getContentResolver().insert(uri, content);
System.out.println("uri=="+uri);
Log.i("TAG","the ringtone uri is :"+newUri);
RingtoneManager.setActualDefaultRingtoneUri (
     context.getApplicationContext(), RingtoneManager.TYPE_RINGTONE,newUri);
                 Toast toast=Toast.makeText(context,"ringtone change succesfully",Toast.LENGTH_SHORT);toast.show();
            }

 });

0 个答案:

没有答案