简体   繁体   中英

Ringtone saving but have to set manually

I have a soundboard app and i am wanting to get the sounds to save as ringtone or notification when the button is long clicked which works fine but then the user would have to go and set the ringtone in the sound tab.

I would like if its possible for the ringtone to save and be set as defualt so it overrides the current ringtone that is being used is this possible.

Thanks in advance.

sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.parse("file://"+path+filename))); 

 File k = new File(path, filename);   
 ContentValues values = new ContentValues();   
 values.put(MediaStore.MediaColumns.DATA, k.getAbsolutePath());   
 values.put(MediaStore.MediaColumns.TITLE, "Benton");   
 values.put(MediaStore.MediaColumns.MIME_TYPE, "audio/ogg");   
 values.put(MediaStore.Audio.Media.ARTIST, "weee");   
 values.put(MediaStore.Audio.Media.IS_RINGTONE, true);   
 values.put(MediaStore.Audio.Media.IS_NOTIFICATION, false);   
 values.put(MediaStore.Audio.Media.IS_ALARM, true);   
 values.put(MediaStore.Audio.Media.IS_MUSIC, false);    

 //Insert it into the database
 this.getContentResolver().insert(MediaStore.Audio.Media.getContentUriForPath(k.getAbsolutePath()), values);

 return true; 
}

Something like,

//Insert it into the database
Uri uri = MediaStore.Audio.Media.getContentUriForPath(file.getAbsolutePath());
Uri newUri = main.getContentResolver().insert(uri, values);

RingtoneManager.setActualDefaultRingtoneUri(
  myActivity,
  RingtoneManager.TYPE_RINGTONE,
  newUri
);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM