Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat
"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 22
    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
    I do not understand English
    I am writing with the help of a google translator

    my blog: https://simartinfo.blogspot.com
    my games:
    https://play.google.com/store/apps/developer?id=AndroidMobileGame+(indie)
    Слава Україні
  • kussakovkussakov Member
    edited April 22
    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 23
    what is maxSdkVersion in you?
    <uses-permission
         android:name="android.permission.WRITE_EXTERNAL_STORAGE"
         android:maxSdkVersion="18" />
    I do not understand English
    I am writing with the help of a google translator

    my blog: https://simartinfo.blogspot.com
    my games:
    https://play.google.com/store/apps/developer?id=AndroidMobileGame+(indie)
    Слава Україні
  • @oleg it is 23 (6.0). If it is say 26 this does not work at all (no access to storage and SD card)
  • MoKaLuxMoKaLux Member
    @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.
  • 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
  • SinisterSoftSinisterSoft Maintainer
    @MoKaLux You can still do it that way, just untick 'generate apk' in the export option.
  • MoKaLuxMoKaLux Member
    edited April 23
    i thought i had to use the old export!
  • MoKaLuxMoKaLux Member
    in fact this is the option that got me into using gideros.
  • SinisterSoftSinisterSoft Maintainer
    No, don't use the old export - just use the new one and untick the generate apk.

    Likes: MoKaLux

    +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
  • SinisterSoftSinisterSoft Maintainer
    I'll write one for Lua Plugins, I've been meaning to do that for a while.

    Likes: dreiko65, MoKaLux, pie

    +1 -1 (+3 / -0 ) Share on Facebook
  • MoKaLuxMoKaLux Member
    edited May 1
    @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 {
    +1 -1 (+2 / -0 ) Share on Facebook
  • kussakovkussakov Member
    edited May 2
    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 2
    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!
  • kussakovkussakov Member
    Yes. The permissions look good, but I can't even see the SD cards using lfs.
Sign In or Register to comment.