gregkorossy / Android-Support-Preference-V7-Fix

Android androidx.preference support library has some issues, this lib tries to fix them.
https://discord.gg/87NVsSK
Apache License 2.0
497 stars 46 forks source link

NumberFormatException in RingtonePreferenceDialogFragmentCompat #203

Open adrcotfas opened 4 years ago

adrcotfas commented 4 years ago

Hello, I'm getting this exception on a Pixel 3.

java.lang.NumberFormatException: 
  at java.lang.Long.parseLong (Long.java:594)
  at java.lang.Long.parseLong (Long.java:636)
  at android.content.ContentUris.parseId (ContentUris.java:89)
  at android.media.RingtoneManager.getRingtonePosition (RingtoneManager.java:513)
  at com.takisoft.preferencex.RingtonePreferenceDialogFragmentCompat.a (RingtonePreferenceDialogFragmentCompat.java:146)
  at com.takisoft.preferencex.RingtonePreferenceDialogFragmentCompat.a (RingtonePreferenceDialogFragmentCompat.java:11)
  at androidx.preference.PreferenceDialogFragmentCompat.a (PreferenceDialogFragmentCompat.java:50)
  at com.takisoft.preferencex.RingtonePreferenceDialogFragmentCompat.access$000 (RingtonePreferenceDialogFragmentCompat.java)
  or                     .access$002 (RingtonePreferenceDialogFragmentCompat.java)
  or                     .access$202 (RingtonePreferenceDialogFragmentCompat.java)
  or                     .access$600 (RingtonePreferenceDialogFragmentCompat.java)
  or                     .access$700 (RingtonePreferenceDialogFragmentCompat.java)
  or                     .addCustomExternalRingtone (RingtonePreferenceDialogFragmentCompat.java)
  or                     .buildAdapter (RingtonePreferenceDialogFragmentCompat.java)
  or                     .buildUniqueFile (RingtonePreferenceDialogFragmentCompat.java)
  or                     .createCursor (RingtonePreferenceDialogFragmentCompat.java)
  or                     .getFileDisplayNameFromUri (RingtonePreferenceDialogFragmentCompat.java)
  or                     .getUniqueExternalFile (RingtonePreferenceDialogFragmentCompat.java)
  or                     .newInstance (RingtonePreferenceDialogFragmentCompat.java)
  or                     .onCreateDialog (RingtonePreferenceDialogFragmentCompat.java)
  or                     .onDialogClosed (RingtonePreferenceDialogFragmentCompat.java)
  or                     .onPrepareDialogBuilder (RingtonePreferenceDialogFragmentCompat.java)
  or                     .splitFileName (RingtonePreferenceDialogFragmentCompat.java)
gregkorossy commented 4 years ago

What Android version do you use?

adrcotfas commented 4 years ago

@Gericop: Android 10 I see this problem on other generations of Pixel and OnePlus 7 Pro too (ANRs & crashes report from Google Play Console).

gregkorossy commented 4 years ago

Do those devices run Android 10 as well?

adrcotfas commented 4 years ago

@Gericop: Yes, there's Android 10 on all of them.

gregkorossy commented 4 years ago

Well, at first look it must be something with the scoped storage introduced in 10. The problem is to add a custom ringtone, the app must copy the file from wherever the user selects it from to the ringtone folder of the phone but it seems like there's no way to do this with scoped storage. A workaround would be to show a save dialog after selecting the file and saving it to the ringtone folder but that's just a pretty terrible UX... Still looking into a proper fix though.

gregkorossy commented 4 years ago

A different solution would be introducing the shared prefs to the game so the custom ringtones would get copied into the app folders (which are available with scoped storage), and the custom ringtone's properties would be saved to the shared prefs.

I wonder how the file explorers will work with the messy scoped storage... I guess they won't.

adrcotfas commented 4 years ago

@Gericop do you know where the list of added custom notification sounds is stored? I would like to clear it in the following case:

I see that if you start fresh with Android 10, a toast is shown when trying to add a custom ringtone which is still better than a completely unusable RingtonePreference like the case above.

Edit: the exception I'm getting comes from onPrepareDialogBuilder where createCursor is called.