How are you dealing with runtime permissions on Android 6.x?

Hi,

As there is changed behaviour of permissions for Android SDK 23 (android 6). It is not enough to declare them only in Android manifest file they should be requested in Appactivity somehow. Is there any example how it is done for Cocos2d-x?

It seems sdkbox now compiled against Android SDK 23 so everyone will need this for new apps :slight_smile: Waiting for you examples - thanks!

1 Like

Hi,

I found this which I think will help you. I’m looking to target newer apis so needed this information.

Good luck,
Katie

And I created a sample project (with callbacks) 2 month ago and shared it on github, because the link mentioned by @katieJ doesn’t have any downloadable sources :wink:

1 Like

The coding suggestions here for setting permissions using Java for Android 6+ are very helpful, but I’m having difficulty implementing it with Cocos2d-x 3.17. The problem is that the Java compiler complains that it can’t find the required imports for android.support.annotation.NonNull, android.support.v4.content.ContextCompat, and android.support.v4.app.ActivityCompat. I think these files used to live in a subdirectory of the the /plugin directory of Cocos2d-x 3.16, but there’s no /plugin directory in my 3.17 download, so where do I find these imports and how do I tell Gradle where to look for them?

Hi @doffen,

you only need to add the support libraries into your Android project: see the example in my configuration. If you need further information, feel free to ask.

Thanks, mars3142 – you’re suggestions and code samples are great. It’s more complex than I expected, cascading through multiple source files with callbacks from java to C++, then from C++ method to C++ method to the user via a lambda function. In my implementation I ended up foregoing the lambda callback (since I only needed the test once at the start of the program), so my C++ callback merely sets a persistent variable that update() polls periodically until it sees how the user answered…

I’ve also discovered a major design difference in the way Android and iOS handle permissions, which may be of interest to developers. In Android, when the user declines permission, you can merely exit the program and ask them again to accept permission next time they run it. In iOS, once the user declines permission (in my case I was asking for microphone input permission), Apple prohibits you from exiting via program control – you have to inform the user and the user has to do the exiting. Then if the user immediately restarts your app, they are not given the opportunity to accept permission once it has been declined. They have to first go to the device’s Settings icon, scroll down in the list of apps to find YOUR app, and reset the permission there.

1 Like