Screen Shots on Android -> writable path?

Hopefully this will be a simple one:

I’m trying to make screen shots work with the sdkbox share plugin. If I try to save the path to /mnt/sdcard/screenshot.png it fails on callback. if I give it an absolute path like the one below if works. However will this path always exist? What’s the best way to find an internal app path that will always be writeable ?

#if (COCOS2D_VERSION > 0x00030000)
   std::string path = "screenshot.png";
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
//  path = "/mnt/sdcard/screenshot.png";
path = "/data/user/0/uk.co.xafield.WoodyQuiz/files/screenshot.png";
#endif
  utils::captureScreen(CC_CALLBACK_2(TwitterModal::afterCaptureScreen, this), path);
#endif

Sorry I have just realised I know the answer to this:

path = FileUtils::getInstance()->getWritablePath() + "screenshot.png";

Hope someone else finds it useful.

And how do you handle this, if your targetSdk is larger the 23? Because since API 23 you need runtime permission to write to /sdcard.

not sure, though I didn’t think I was writing to the SD card path.

you should check/ request in AppActivity for write/read permission - so best way would be to compile against SDK 22 :slight_smile:

Against API 22 is no option, because right now API 25 is the latest.

Will you ever be stuck in old API-level? And as a user, I want to disable permission, so I prefer apps/games with at least API 23.

I think it is bad idea to user API 25 for example:) you making not native apps - so you will not use latest functionality of it. And older SDK have better compability with older devices. Also regarding permissions it will be headache for you - you have leaderbors/share buttons - but they will not work because user not granted access for them…

Otherwise :slight_smile: welcome to check
https://developer.android.com/training/permissions/requesting.html

if it works share you code :wink: we also want at some point move to v23 but not now - it still to early.

You are mixing target sdk with min sdk. The native code is indeed compiled against API 19 (min sdk), but the Java part is against API 25 (target sdk).

I’m writing Android apps (with Java) for my living, so I know how to use runtime permissions. But now I wand to build games with cocos2d-x and I’m confused, how this will be callback to the native part (because it’s an async call).

Maybe I really build a demo “hello world” with runtime permission. This will be a good training for the upcoming weekend :wink:

1 Like

Yeah, I’m already asked SDKBOX to handle this, not sure if they will do it soon or not - as SDKBOX by default now adding in gradle Target SDK 23. I was trying with this permissions runtime but app crashed time to time due it. So it would be good to have working hello world.

I think for Android best is Min sdk 15/16 and Target 22 for now - at least for Cocos - as there is lot of relation to NDK bla bla versions and this setup is more or less stable in terms of crashes.

For native for sure is cool to use latest SDK to get more cool features into app not game:)

There is reference to turial I was trying:

1 Like

Hi @energyy, as promised I build a sample app which ask for a permission and shows the return value within the cocos2d-x world. The main difference between my and the sample you showed me, is that my app doesn’t request the permission at app start and can store the return value for further action.

If I find some time, I will also write a brief blog post about it, so that you don’t have to debug or read all the code to understand it. But right now, it’s a real working sample.

Link: https://github.com/mars3142/cocos2dx-runtime-permission

thanks, will have a look on it:)