Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to set music files which are not in Media Store as ringtone
    primarykey
    data
    text
    <p>Before Jelly Bean level 18 I can use music files which are not in Media store (for example, a <code>private</code> .mp3 file in a folder contains <code>.nomedia</code> file, so Media Scanner does not scan this folder and does not know about this file) but from Android 4.3 (tested on Nexus 4) I can not do that, it only works for music files which are already scanned by Media Scanner.</p> <p>The real reason of this problem is I cannot insert ContentValues with MediaColumns.DATA is a absolute path of a file not scanned by Media Scanner, insert method always return null.</p> <pre><code>Uri newUri = getCR().insert(uri, contentValues); // returns null in Android 4.3 </code></pre> <p>Does anyone have a workaround to use a private file (not scanned and not recognized by Media Scanner) as ringtone?</p> <p>Here is how I set ringtone:</p> <pre><code> File ringtoneFile = new File(audio.getPath()); ContentValues cv = new ContentValues(); cv.put(MediaColumns.DATA, ringtoneFile.getAbsolutePath()); cv.put(MediaColumns.TITLE, audio.getTitle()); cv.put(MediaColumns.MIME_TYPE, "audio/*"); if (audio.getArtist() != null) cv.put(Media.ARTIST, audio.getArtist()); cv.put(Media.IS_RINGTONE, true); cv.put(Media.IS_NOTIFICATION, false); cv.put(Media.IS_ALARM, false); cv.put(Media.IS_MUSIC, false); Uri uri = Media.getContentUriForPath(ringtoneFile.getAbsolutePath()); Uri newUri = getCR().insert(uri, cv); ////return null in Android 4.3 if (newUri == null) { Cursor c = getCR().query(uri, new String[] { Media._ID }, Media.DATA + "=?", new String[] { ringtoneFile.getAbsolutePath() }, null); long id = -1; if (c != null &amp;&amp; c.moveToFirst()) { id = c.getLong(c.getColumnIndex(Media._ID)); newUri = Uri.parse(uri.toString() + "/" + id); c.close(); } } if (newUri != null) { RingtoneManager.setActualDefaultRingtoneUri(getAppContext(), RingtoneManager.TYPE_RINGTONE, newUri); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload