Android: How to save to Pictures folder

About Monkey 2 Forums Monkey 2 Programming Help Android: How to save to Pictures folder

This topic contains 10 replies, has 4 voices, and was last updated by  Nalle 1 week, 2 days ago.

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #15545

    Nalle
    Participant

    Hello everyone,

    How in Monkey2 the Pictures folder of Android systems can be retrieved?

    I’m currently using path “sdcard/Pictures/”, but this probably isn’t the best way to do it.

    I would like to have the pictures to be visible with computer too, so that it would be easy to transfer the files from Android device to computer.

    The way I’m currently done it, the user has to copy or move first the file on Android device, which makes it visible to a computer too.

    #15550

    nerobot
    Participant

    Hi. There is the function  GetSpecialDir:String( name:String ) but it understand only “internal” and “external” params for android,

    but you can extend it by changing this file

    /monkey2/modules/std/filesystem/native/Monkey2FileSystem.java

    add one more else  branch:

    and rebuild std module for android target.

    #15551

    nerobot
    Participant

    I will test and add realisation for all external dirs.

    #15639

    Nalle
    Participant

    With my new Samsung Galaxy A6+ saving to Pictures folder doesn’t work. I checked SavePixmap state from the debugger, it was false and nothing was saved. Has anyone else tried this?

    #15641

    Mark Sibly
    Keymaster

    It may be a permissions issue, try something like this…

    RequestPermissions( New String[][(“android.permission.WRITE_EXTERNAL_STORAGE”),Lambda( results:UInt[] )

    End )

    I have no idea if this is the correct permission to ask for though, more here:

    https://developer.android.com/reference/android/Manifest.permission

    #15644

    Nalle
    Participant

    As default there is in the Android Manifest this permission: WRITE_EXTERNAL_STORAGE

    I also thought, that could it be permissions issue, because ..Environment.getExternalStoragePublicDirectory( Environment.DIRECTORY_PICTURES ) is the correct way to get the Pictures folder.

    #15645

    SekaiChi
    Participant

    if setting it to targetSdkVersion 21 works fine, then we have the same problem. working on it

    #15646

    SekaiChi
    Participant

    this seem to be what has changed to increase the security in Android filesystem, i dont have any pacakaged solution yet as i dont have much time before Christmas. But it might give an idea to ppl.

    https://developer.android.com/reference/android/support/v4/content/FileProvider

    #15671

    Nalle
    Participant

    From Android version 6 (API >= 23) one must ask at run-time permission for example to Pictures folder.

    This was my first try to do Android coding inside the Android Studio and I came up with this not working skeleton, that is based on Google’s example code:

    Edit: Also this in addition:

     

    Has anyone a working solution?

    Working solution should ask the user, if the user agrees to app’s writing to external storage.

    edit: Link to original code: https://developer.android.com/training/permissions/requesting#java

    #15672

    Nalle
    Participant

    I made a new code, this little code (needs some improvement) seems to work.

    It prompts the user (system feature) if the app may write to external storage, after permission, when the permission is granted, the picture is saved to Pictures folder!

    We should add proper code to Monkey2 modules to get more Android features like Camera.

    #15674

    Nalle
    Participant

    I found this old thread: http://monkeycoder.co.nz/forums/topic/android-permissions/

    The permissions can be asked simply in nice Monkey2 code. 🙂

    Though, I had at first problem with the following line:

    RequestPermissions(permissions,Lambda( results:Int[] )

    Error : Can’t find overload for ‘RequestPermissions’ with argument types (monkey.types.String[],Void(monkey.types.Int[]))

    If it is changed to: RequestPermissions( permissions,Lambda( results:ResultType[] ) it can be compiled.

Viewing 11 posts - 1 through 11 (of 11 total)

You must be logged in to reply to this topic.