This is a simple question, and probably a simple answer but there is a huge amount of context.
The Question: does setActualDefaultRingtoneUri()
still work in API 23? because I can't get it to function
The Context:
I've set up AndroidManifest.xml
with
<uses-permission android:name="android.permission.WRITE_SETTINGS"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
The app self assigns the permissions with this code
public void desirePermissionCode()
{
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !Settings.System.canWrite(this)) {
new AlertDialog.Builder(this)
.setMessage("Please Assign Meep Meep Write Permissions")
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Intent intent = new Intent(android.provider.Settings.ACTION_MANAGE_WRITE_SETTINGS);
intent.setData(Uri.parse("package:" + getPackageName()));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
try {
startActivity(intent);
} catch (Exception e) {
Log.e("MainActivity", "error starting permission intent", e);
}
}
})
.show();
return;
}
}
I then have a simple 2 button demo: one with this (doesn't work)
Uri uri = Uri.parse("android.resource://" + getPackageName() + "/raw/meepmeep");
grantUriPermission("com.android.systemui", uri,
Intent.FLAG_GRANT_READ_URI_PERMISSION);
RingtoneManager.setActualDefaultRingtoneUri(
MainActivity.this,
RingtoneManager.TYPE_RINGTONE,
uri
);
and one with this (does work)
MediaPlayer mpintro;
mpintro = MediaPlayer.create(me, Uri.parse("android.resource://"+getPackageName()+"/raw/meepmeep"));
mpintro.start();
can someone explain to me why, when the 2 permissions are added, and the meepmeep.mp3
is in the res folder, so why does the event fire to play the sound in the app but not assign the ringtone in RingtoneManager.setActualDefaultRingtoneUri
clearly
shows me doing this, thank you, but it doesn't work – Socha