mdicosimo
mdicosimo

Reputation: 834

Android O+: Some phones seem to lack the option to change sound type for notifications

Again about notification sound on Android O+. There are some phones where the "notification settings" window doesn't show the sound selection button (and not even the vibration button). Here are a couple examples:

(not minor brands... I would say)

They were tested with Gmail app (menu -> Settings -> account -> Notification settings) on Android 8.

Here Android O - Notification Channels - Change Vibration Pattern or Sound Type is a solution to avoid the "standard" window, but why should we reinvent the wheel?

Is there any other option that I'm missing?

Thank you,

Max

P.S. Here is a screenshot from a Honor 9 / Android 8.0.0. Channel name is "Mail" ("Posta" in Italian). For sound ("Suoneria" in Italian) there is only an On/Off switch. GMail -> Settings -> account -> Notification Settings

Upvotes: 4

Views: 322

Answers (1)

Roy Solberg
Roy Solberg

Reputation: 19723

It's a mess. You need to add workarounds for the different brands/devices. This is the flow we're using to deal with it:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && !isDeviceWithWorkaround()) {
    // Send to notification channel settings (See https://developer.android.com/training/notify-user/channels#UpdateChannel)
}else{
    Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
    intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_NOTIFICATION);
    intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE, "Sound");
    intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, Uri.parse(someExistingRingTone));
    if (isDeviceWithWorkaround()) {
        intent.setPackage("com.android.providers.media"); 
    }
    try {
        startActivityForResult(intent, reqCode);
    } catch (ActivityNotFoundException e) {
        if (isDeviceWithWorkaround()) {
            Log.i(TAG, "Failed to find preferred package [" + intent.getPackage() + "]. Trying again without package.");
            intent.setPackage(null);
            startActivity(intent);
        }
    }
}

So what's happening is that if it's a device with a known issue as you talk about we send them to the good old ringtone picker.

I believe that the package com.android.providers.media doesn't have an activity to start on stock Android, but on Huawei it then opens the Media Store where we get back a ringtone URI that can be used as notification sound. (We don't want the user to end up in some other ringtone picker that might not work. We have always recommended our users to use https://play.google.com/store/apps/details?id=com.angryredplanet.android.rings_extended but it won't work with Huawei on Android 8).

Upvotes: 0

Related Questions