Obsolete
Status Update
Comments
am...@google.com <am...@google.com> #2
Supporting RingtonePreference would have required porting over some awkward plumbing to route the activity result back to the preference object, and it made more sense to just leave it in the hands of the app developer to handle this by overriding onPreferenceTreeClick and then launching the ringtone activity themselves (see RingtoneManager.ACTION_RINGTONE_PICKER).
ar...@google.com <ar...@google.com> #3
That would be nice to point out in the API docs. Here's how I implemented the workaround described:
In you preferences XML resource, change RingtonePreference to Preference. Then, in your implementation of PreferenceFragment, add:
@Override
public boolean onPreferenceTreeClick(Preference preference) {
if (preference.getKey().equals(KEY_RINGTONE_PREFERENCE)) {
Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_NOTIFICATION);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, true);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_DEFAULT_URI, Settings.System.DEFAULT_NOTIFICATION_URI);
String existingValue = getRingtonePreferenceValue(); // TODO
if (existingValue != null) {
if (existingValue.length() == 0) {
// Select "Silent"
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, (Uri) null);
} else {
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, Uri.parse(existingValue));
}
} else {
// No ringtone has been selected, set to the default
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, Settings.System.DEFAULT_NOTIFICATION_URI);
}
startActivityForResult(intent, REQUEST_CODE_ALERT_RINGTONE);
return true;
} else {
return super.onPreferenceTreeClick(preference);
}
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_CODE_ALERT_RINGTONE && data != null) {
Uri ringtone = data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
if (ringtone != null) {
setRingtonPreferenceValue(ringtone.toString()); // TODO
} else {
// "Silent" was selected
setRingtonPreferenceValue(""); // TODO
}
} else {
super.onActivityResult(requestCode, resultCode, data);
}
}
In you preferences XML resource, change RingtonePreference to Preference. Then, in your implementation of PreferenceFragment, add:
@Override
public boolean onPreferenceTreeClick(Preference preference) {
if (preference.getKey().equals(KEY_RINGTONE_PREFERENCE)) {
Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_NOTIFICATION);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, true);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_DEFAULT_URI, Settings.System.DEFAULT_NOTIFICATION_URI);
String existingValue = getRingtonePreferenceValue(); // TODO
if (existingValue != null) {
if (existingValue.length() == 0) {
// Select "Silent"
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, (Uri) null);
} else {
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, Uri.parse(existingValue));
}
} else {
// No ringtone has been selected, set to the default
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, Settings.System.DEFAULT_NOTIFICATION_URI);
}
startActivityForResult(intent, REQUEST_CODE_ALERT_RINGTONE);
return true;
} else {
return super.onPreferenceTreeClick(preference);
}
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_CODE_ALERT_RINGTONE && data != null) {
Uri ringtone = data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
if (ringtone != null) {
setRingtonPreferenceValue(ringtone.toString()); // TODO
} else {
// "Silent" was selected
setRingtonPreferenceValue(""); // TODO
}
} else {
super.onActivityResult(requestCode, resultCode, data);
}
}
sa...@google.com <sa...@google.com> #4
Thank you for your feedback. We will be closing the issue as “won't fix - obsolete”. If this issue is still reproducible, we request that you log a new issue along with the bug report here https://goo.gl/TbMiIO and reference this bug for context.
Description
QPP1.190205.018.B4
* Is this a regression from P to Q?
Not applicable, new API to Android Q
* What device are you using? (for example, Pixel XL)
Pixel
* What are the steps to reproduce the problem? (Please provide the minimal reproducible test case.)
Step #1: UnZIP the attached RoleNonReversal-20190324.zip file, import it into your favorite IDE, and run it on an Android Q device.
Step #2: Notice that the really big button is enabled. It is enabled if roleManager.isRoleHeld(RoleManager.ROLE_MUSIC) returns false. Since this app was just installed, it does not hold any role, so roleManager.isRoleHeld(RoleManager.ROLE_MUSIC) returns false, and the really big button is enabled.
Step #3: Click the really big button.
Step #4: When Android Q asks if you want to make this app be your music player, click OK.
Step #5: Notice that the really big button is now disabled, as RoleManager is reporting that the app holds ROLE_MUSIC.
Step #6: Go to Settings > Apps & notifications > RoleNonReversal > Permissions > Music, and toggle that "permission" to Deny.
Step #7: Terminate the process for the RoleNonReversal app (should already be terminated by Android Q, but make sure it's gone).
Step #8: Run the RoleNonReversal app again.
* Issue Category e.g. Framework (platform), NDK (platform), Hardware (CPU, GPU, Sensor, Camera), ART (platform), Runtime Permissions etc
Framework
* What was the expected result?
The really big button should be enabled, because roleManager.isRoleHeld(RoleManager.ROLE_MUSIC) should return false, since the role is no longer held.
* Can you provide the API document where this expected behavior is explained?
See the RoleManager JavaDocs.
* What was the actual result?
The really big button is still disabled, as roleManager.isRoleHeld(RoleManager.ROLE_MUSIC) is returning true.