Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
"Require" Plugin — Gideros Forum

"Require" Plugin

Guys,

Gideros comes with "Require" plugin for Android.
It looks like this is not exactly a plugin, but a way to add some permissions to the manifest.
My app needs to read files from the phone storage/SD card and process them.
I used the "Require" plugin to add "App needs to to write external storage" permission.
It adds it to the manifest (it only work for Android target 6.0 or lower by the way since what it adds is depreciated new newer versions of Android).

So when I set my target as Android 6 it adds "Storage" to app permissions.
The problem is that Android does not ask the user to Allow this permission.
It adds "Storage" to permissions, but the user has to go to App settings->Permissions and enable it manually. The "Allow" android dialog never comes.
The question is:
Do you know how to force this "Allow" dialog out of Gideros?

Thanks!

Comments

  • olegoleg Member
    edited April 2019
    you can edit require.gplugin

    as you need

    If you look at the 'requires' plugin (in the program files>gideros>all plugins folder) then you can see how we add the various patches to the Android files. They basically do a find and replace text on various files.

    https://github.com/razorback456/gideros_tools/blob/master/require.gplugin
    my games:
    https://play.google.com/store/apps/developer?id=razorback456
    мій блог по гідерос https://simartinfo.blogspot.com
    Слава Україні!
  • kussakovkussakov Member
    edited April 2019
    Thanks, I checked it out, but I actually meant something else:
    Is there a way in Gideros to evoke ContextCompat.checkSelfPermission() and ActivityCompat.requestPermissions with specific permission, because having the permissions in the manifest does not help in some cases. The user has no way of turning them on inside the app (the popup does not appear).
    I know that some of the plugins have code to check for specific permission (camera microphone), but the LFS plugin, for example, does not check for "Storage" permission (since it is low level and written in C I guess).

    I see that there is some Example plugin that "Send a start event, wifi count and needed permissions. Can send a stop event."
    Do you know if I can use this to ask for Storage permissions and if so how?

    Thanks!
  • olegoleg Member
    edited April 2019
    what is maxSdkVersion in you?
    <uses-permission
         android:name="android.permission.WRITE_EXTERNAL_STORAGE"
         android:maxSdkVersion="18" />
    my games:
    https://play.google.com/store/apps/developer?id=razorback456
    мій блог по гідерос https://simartinfo.blogspot.com
    Слава Україні!
  • @oleg it is 23 (6.0). If it is say 26 this does not work at all (no access to storage and SD card)
  • @kussakov hello there,

    In android studio to request user permission through an app, you need to write some java code requesting those permissions. Now that google tells us to target android version 26 minimum I believe we need to implement this in all our apps.

    I don't know gideros that much but one of my first test was to export a gideros sample to android studio. Then I had to update quite a few things like gradle and so.

    Once all the updating was done in android studio I could write my java code and successfully run the demo on my android phone. You may try this way?

    I wish gideros don't give up this option as it can be handy.
    my growING GIDEROS github repositories: https://github.com/mokalux?tab=repositories
  • hgy29hgy29 Maintainer
    Accepted Answer
    Yes, WRITE_EXTERNAL_STORAGE is one of the dangerous permissions since android 23, that is no longer granted automatically even if specified in the manifest. You have to request it through Java code, and since it is asynchronous you further need to check if the permission was granted by the user.

    There is no way to do it with current Gideros APIs, I reckon the relevant Java code and lua bindings should be added to require plugin.
    +1 -1 (+3 / -0 )Share on Facebook
  • @MoKaLux You can still do it that way, just untick 'generate apk' in the export option.
    Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
    https://deluxepixel.com
  • MoKaLuxMoKaLux Member
    edited April 2019
    i thought i had to use the old export!
    my growING GIDEROS github repositories: https://github.com/mokalux?tab=repositories
  • in fact this is the option that got me into using gideros.
    my growING GIDEROS github repositories: https://github.com/mokalux?tab=repositories
  • No, don't use the old export - just use the new one and untick the generate apk.

    Likes: MoKaLux

    Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
    https://deluxepixel.com
    +1 -1 (+1 / -0 )Share on Facebook
  • Got it @hgy29. Yes - they depreciated WRITE_EXTERNAL_STORAGE.

    I will probably try to add some java code to one of the existing plugins. I don't know exactly how to add new plugins in Android (only in iOS). Hope I don't have to change some C code, because I don't know how to compile it for Android.

    By the way: Is there a tutorial of how to make plugin for Android - that has callbacks and stuff and how to compile it? I can try that...

    Thanks
  • antixantix Member
    @kussakov Unfirtunately there doesn't seem to be any uptodate easy to follow good tutorial on making plugins for Gideros. It's one of those things that it really needs.

    Likes: Apollo14

    +1 -1 (+1 / -0 )Share on Facebook
  • hgy29hgy29 Maintainer
    antix said:

    @kussakov Unfirtunately there doesn't seem to be any uptodate easy to follow good tutorial on making plugins for Gideros. It's one of those things that it really needs.

    I'd be happy to help anyone who wants to do that. I tried many times to write a guide but I just don't know where to start.

    Likes: dreiko65, MoKaLux

    +1 -1 (+2 / -0 )Share on Facebook
  • I'll write one for Lua Plugins, I've been meaning to do that for a while.

    Likes: dreiko65, MoKaLux, pie

    Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
    https://deluxepixel.com
    +1 -1 (+3 / -0 )Share on Facebook
  • MoKaLuxMoKaLux Member
    edited May 2019
    @kussakov hello there,

    I have some java code for you.
    1- export your gideros project to android studio
    2- in the onCreate method:
            // ask permission to write
            if (Build.VERSION.SDK_INT >= 23) {
                if (isPermissionWriteES()) {
                    // permission OK can save image
                    // return; // THIS RETURN CALL BREAKS THE APP!!!
                } else {
                    requestPermissionWES();
                }
            }
    3- then the other functions to ask the user the permissions:
        private boolean isPermissionWriteES() {
            int result = ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE);
            return result == PackageManager.PERMISSION_GRANTED;
        }
     
        private void requestPermissionWES() {
            if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
                zprefsutil.myShowToast(getApplicationContext().getString(R.string.permissionrw), 1);
                ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
                        PERMISSION_WRITE_EXTERNAL_STORAGE);
            } else {
                ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
                        PERMISSION_WRITE_EXTERNAL_STORAGE);
            }
        }
    @SuppressLint("Override")
    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String permissions[], @NonNull int[] grantResults) {
    switch (requestCode) {
    case PERMISSION_WRITE_EXTERNAL_STORAGE:
    if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
    zprefsutil.myShowToast("SUPER.", 1);
    } else {
    zprefsutil.myShowToast(getApplicationContext().getString(R.string.nopermissionrw), 1);
    }
    break;
    default:
    break;
    }
    }



    Hope that can help you.
    nb1: i could not format the last piece of code because of special characters
    nb2: you need to create the class with:
    public class A01_MenuActivity extends Activity implements OnClickListener, OnRequestPermissionsResultCallback {
    my growING GIDEROS github repositories: https://github.com/mokalux?tab=repositories
    +1 -1 (+2 / -0 )Share on Facebook
  • kussakovkussakov Member
    edited May 2019
    Thanks @MoKaLux!
    I added the code to my main activity class (instead of to some plugin java code).
    (Needed to add:
    import android.support.v4.app.ActivityCompat;
    import android.support.v4.content.ContextCompat;
    and this do the build.gradle: implementation "com.android.support:support-v4:27.+"
    and some static variable for PERMISSION_WRITE_EXTERNAL_STORAGE)

    Now the "permission" dialog pops and asks for storage permission and when I "allow" - it sets the storage permissions in the app permission settings.
    I do not have control in the lua (since it is not a plugin), but it sets the permission.

    The problem is that the app has no access to the storage at all. Even though the permission is now set... I use LuaFileSystem calls and Gideros Texture.new to access the SD card content.
    It works if the targetSdkVersion is 23.

    Likes: MoKaLux

    +1 -1 (+1 / -0 )Share on Facebook
  • MoKaLuxMoKaLux Member
    edited May 2019
    so you mean that asking the user permission is ok but you cannot save to android?

    It is a feature I am planning to use later on and that doesn't work above sdk 23? Damn google! They really want us to use android studio!
    my growING GIDEROS github repositories: https://github.com/mokalux?tab=repositories
  • Yes. The permissions look good, but I can't even see the SD cards using lfs.
  • @kussakov I HAVE A SURPRISE FOR YOU. I need to tidy up my code and you can see the gideros magic at its best.

    Are you in a hurry?

    Likes: Apollo14

    my growING GIDEROS github repositories: https://github.com/mokalux?tab=repositories
    +1 -1 (+1 / -0 )Share on Facebook
  • hgy29hgy29 Maintainer
    This reminds that I forgot to tell you: I added two news calls to core gideros (in next release) to check if a permission was granted and request new permissions. Of course they will be implemented only for Android.

    Likes: Apollo14, MoKaLux, oleg

    +1 -1 (+3 / -0 )Share on Facebook
  • MoKaLuxMoKaLux Member
    edited August 2019
    ok this is a solution:
    --require Media plugin
    require "media"
     
    -- draw your gfx (here I draw a simple pixel)
    local source = Pixel.new(0xffff00, 0.75, 128, 128)
    -- create a render target and draw to it
    local rt = RenderTarget.new(source:getWidth(), source:getHeight())
    rt:draw(source)
    -- save your render target to gideros documents folder
    local myfilepath = "|D|mysavedpicture2.png"
    rt:save(myfilepath)
    -- create a new media and save your gfx
    -- android saved path = internal storage/pictures
    -- NEED permission write external storage
    local media = Media.new(myfilepath)
    mediamanager:postPicture(myfilepath)
     
    -- show your gfx on stage
    local mybmprt = Bitmap.new(rt)
    mybmprt:setPosition(64, 64)
    stage:addChild(mybmprt)

    I have tested it on my Samsung J6 running android 9.
    It saves your gfx to android pictures folder and the name of the file is: YYMMDD_HHMMSS_gideros.jpg

    On windows 10, this will open the file explorer where you can change the file name.

    Voilà.

    Likes: oleg, Apollo14

    my growING GIDEROS github repositories: https://github.com/mokalux?tab=repositories
    +1 -1 (+2 / -0 )Share on Facebook
  • Apollo14Apollo14 Member
    edited August 2019
    This is nice!! Thanks! But don't we need to pre-declare 'mediamanager'?
    mediamanager:postPicture(myfilepath) --I see it's the only mentioning of mediamanager, it wasn't declared anywhere?
    > Newcomers roadmap: from where to start learning Gideros
    "What one programmer can do in one month, two programmers can do in two months." - Fred Brooks
    “The more you do coding stuff, the better you get at it.” - Aristotle (322 BC)
  • no you don't because it is part of the media plugin.
    This sample code is ready to use: copy/paste and voilà.
    (you need to create a project of course!)

    On windows that will open a save file dialog. On mac I don't know. On iPhone I don't know too.

    Likes: Apollo14

    my growING GIDEROS github repositories: https://github.com/mokalux?tab=repositories
    +1 -1 (+1 / -0 )Share on Facebook
Sign In or Register to comment.