Merge changes I7907f0a3,Iec46c80b
* changes: When the mUri is null,it will happen NullPointerException. Ringtone uri should add type query
This commit is contained in:
@@ -372,7 +372,7 @@ public class Ringtone {
|
|||||||
AudioAttributes.toLegacyStreamType(mAudioAttributes)) != 0) {
|
AudioAttributes.toLegacyStreamType(mAudioAttributes)) != 0) {
|
||||||
startLocalPlayer();
|
startLocalPlayer();
|
||||||
}
|
}
|
||||||
} else if (mAllowRemote && (mRemotePlayer != null)) {
|
} else if (mAllowRemote && (mRemotePlayer != null) && (mUri != null)) {
|
||||||
final Uri canonicalUri = mUri.getCanonicalUri();
|
final Uri canonicalUri = mUri.getCanonicalUri();
|
||||||
final boolean looping;
|
final boolean looping;
|
||||||
final float volume;
|
final float volume;
|
||||||
|
|||||||
@@ -1130,11 +1130,13 @@ public class RingtoneManager {
|
|||||||
|
|
||||||
// Try finding the scanned ringtone
|
// Try finding the scanned ringtone
|
||||||
final String filename = getDefaultRingtoneFilename(type);
|
final String filename = getDefaultRingtoneFilename(type);
|
||||||
|
final String whichAudio = getQueryStringForType(type);
|
||||||
|
final String where = MediaColumns.DISPLAY_NAME + "=? AND " + whichAudio + "=?";
|
||||||
final Uri baseUri = MediaStore.Audio.Media.INTERNAL_CONTENT_URI;
|
final Uri baseUri = MediaStore.Audio.Media.INTERNAL_CONTENT_URI;
|
||||||
try (Cursor cursor = context.getContentResolver().query(baseUri,
|
try (Cursor cursor = context.getContentResolver().query(baseUri,
|
||||||
new String[] { MediaColumns._ID },
|
new String[] { MediaColumns._ID },
|
||||||
MediaColumns.DISPLAY_NAME + "=?",
|
where,
|
||||||
new String[] { filename }, null)) {
|
new String[] { filename, "1" }, null)) {
|
||||||
if (cursor.moveToFirst()) {
|
if (cursor.moveToFirst()) {
|
||||||
final Uri ringtoneUri = context.getContentResolver().canonicalizeOrElse(
|
final Uri ringtoneUri = context.getContentResolver().canonicalizeOrElse(
|
||||||
ContentUris.withAppendedId(baseUri, cursor.getLong(0)));
|
ContentUris.withAppendedId(baseUri, cursor.getLong(0)));
|
||||||
@@ -1162,4 +1164,13 @@ public class RingtoneManager {
|
|||||||
default: throw new IllegalArgumentException();
|
default: throw new IllegalArgumentException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static String getQueryStringForType(int type) {
|
||||||
|
switch (type) {
|
||||||
|
case TYPE_RINGTONE: return MediaStore.Audio.AudioColumns.IS_RINGTONE;
|
||||||
|
case TYPE_NOTIFICATION: return MediaStore.Audio.AudioColumns.IS_NOTIFICATION;
|
||||||
|
case TYPE_ALARM: return MediaStore.Audio.AudioColumns.IS_ALARM;
|
||||||
|
default: throw new IllegalArgumentException();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user