Created
November 1, 2012 09:02
-
-
Save ufo22940268/3992587 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static Uri convertToRingtoneUri(Context context, String customRingtone) { | |
if (TextUtils.isEmpty(customRingtone) || SILENT_RINGTONE_LABEL.equals(customRingtone)) { | |
return null; | |
} | |
//Query internal media. | |
ContentResolver cr = context.getContentResolver(); | |
Cursor c = cr.query(Media.INTERNAL_CONTENT_URI, | |
new String[]{Media._ID}, | |
Media.DATA + " = ?", | |
new String[]{customRingtone}, | |
null); | |
Uri uri = null; | |
if (c != null) { | |
if (c.moveToFirst()) { | |
long id = c.getLong(0); | |
uri = ContentUris.withAppendedId(Media.INTERNAL_CONTENT_URI, id); | |
} | |
c.close(); | |
} | |
//Query external media. | |
if (uri == null) { | |
c = cr.query(Media.EXTERNAL_CONTENT_URI, | |
new String[]{Media._ID}, | |
Media.DATA + " = ?", | |
new String[]{customRingtone}, | |
null); | |
if (c != null) { | |
if (c.moveToFirst()) { | |
long id = c.getLong(0); | |
uri = ContentUris.withAppendedId(Media.EXTERNAL_CONTENT_URI, id); | |
} | |
c.close(); | |
} | |
} | |
if (uri != null) { | |
return uri; | |
} else { | |
return null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment