RingtoneManager: Don't crash if the ringtone doesn't have a numerical ID
When changing the notification sound for some apps with app-provided sounds, the notification URI doesn't have a numerical ID. For example, Outlook's email notification URI has the id 'new_email' Test: m, outlook doesn't crash anymore, test google calendar Change-Id: Ibf0c6f2f13e1c76ce02784165b97b92e8f7e432c
This commit is contained in:
committed by
Luca Stefani
parent
79b6ad735b
commit
fb3973a917
@@ -509,15 +509,19 @@ public class RingtoneManager {
|
||||
* @return The position of the {@link Uri}, or -1 if it cannot be found.
|
||||
*/
|
||||
public int getRingtonePosition(Uri ringtoneUri) {
|
||||
if (ringtoneUri == null) return -1;
|
||||
final long ringtoneId = ContentUris.parseId(ringtoneUri);
|
||||
|
||||
final Cursor cursor = getCursor();
|
||||
cursor.moveToPosition(-1);
|
||||
while (cursor.moveToNext()) {
|
||||
if (ringtoneId == cursor.getLong(ID_COLUMN_INDEX)) {
|
||||
return cursor.getPosition();
|
||||
try {
|
||||
if (ringtoneUri == null) return -1;
|
||||
final long ringtoneId = ContentUris.parseId(ringtoneUri);
|
||||
|
||||
final Cursor cursor = getCursor();
|
||||
cursor.moveToPosition(-1);
|
||||
while (cursor.moveToNext()) {
|
||||
if (ringtoneId == cursor.getLong(ID_COLUMN_INDEX)) {
|
||||
return cursor.getPosition();
|
||||
}
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
Log.e(TAG, "NumberFormatException while getting ringtone position, returning -1", e);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user