Android TV undocumented SDK 22 permission crash

Published by Leff on

Recently during a development of our Android TV application we’be stumbled upon the problem that has crashed emulator with SDK>=22, writing on React Native 0.53.

The problem was with the intent that started an app. It just crashed with an unknown to history of mankind error, android.settings.action.MANAGE_OVERLAY_PERMISSION.

We could not find anything viable on the net, just few chinese websites which had the method we needed, but we really tried to make our app work without black magic with settings

Also here from react-native
I found that this could be some android rom issue, maybe the rom offered by the Mobile phone manufacturers lost the user grant UI.The App crashes As long as it request permission. And I go to Settings and grant some permission, the App runs well.

wut? Did ROM lose the fact that user had been granted UI? It blows my fucking mind how people can close this bug report with such a shitty explanation, if we consider it an explanation at all.

Here we go.
Since SDK 22 Android requires permission during runtime. And Android just seems to not being able to find instance of UI or something. We looked at the react-native manifests and found that we didn’t grant our app to read external storage, even though all react-native manifests do grant it.

Therefore, we just add:

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

Now it seems to work, we tested it on Xiaomi Mi Box and emulator, everything seems to work fine now on both phones and TV.

In case it didn’t do to you, this stackoverflow answer contains that black magic method fix

Comment

Basically you can't just check all rom which have issues with settings. The code above works fine in android N as well. I tested this myself.
What you can do is put your code inside a try catch block and when you enters the catch block show user a dialog which asks him to give overlay permission manually instead taking him directly to the settings page.
There are some roms basically the custom roms which have issues with some system settings so this is the best approach you can use to tackle these situations.

[collapse]

if (!Settings.canDrawOverlays(this)) {
Intent localIntent = new Intent("android.settings.action.MANAGE_OVERLAY_PERMISSION");
localIntent.setData(Uri.parse("package:" + getPackageName()));
localIntent.setFlags(268435456);
startActivity(localIntent);
}

It is a very weird error and I wish we had some documentation.