Android/MonoDroid custom Ringtones question -
i trying figure out how take audio file assets folder (included androidasset) , add list of ringtones see when make call:
this.startactivity(new intent(android.media.ringtonemanager.actionringtonepicker));
i adding ringtone via call:
inputstream inputstream = assets.open("filename.mp3");
does know how accomplished? have been searching on , haven’t figured out. thank you
something this:
private void setasringtone(){ try { //open inputstream assets inputstream fis = assets.open("filename.mp3"); if (fis == null) return; //open file save ringtone in sd (/sdcard/android/data/com.your.package/) file path = new file(environment.getexternalstoragedirectory().getabsolutepath() + "/android/data/com.your.package/"); if(!path.exists()) path.mkdirs(); //create proper file file f = new file(path, "yourtitle" + ".mp3"); //dump inputstream in file outputstream fos = new fileoutputstream(f); byte[] buf =new byte[1024]; int len; while((len=fis.read(buf))>0){ fos.write(buf,0,len); } fos.close(); fis.close(); //here metadata of ringtone contentvalues values = new contentvalues(); values.put(mediastore.mediacolumns.data, f.getabsolutepath()); values.put(mediastore.mediacolumns.title, "yourtitle"); values.put(mediastore.mediacolumns.size, f.length()); values.put(mediastore.mediacolumns.mime_type, "audio/mp3"); values.put(mediastore.audio.media.artist, "yourartist"); //values.put(mediastore.audio.media.duration, ""); not needed values.put(mediastore.audio.media.is_ringtone, true); values.put(mediastore.audio.media.is_notification, false); values.put(mediastore.audio.media.is_alarm, false); values.put(mediastore.audio.media.is_music, false); //we put in ddbb of mediastore uri uri = mediastore.audio.media.getcontenturiforpath(f.getabsolutepath()); uri newuri = getbasecontext().getcontentresolver().insert(uri, values); //set default ringtonemanager.setactualdefaultringtoneuri( getbasecontext(), ringtonemanager.type_ringtone, newuri); } catch (filenotfoundexception e) { } catch (ioexception e) { } }
Comments
Post a Comment