Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
is Gmedia working on Android? — Gideros Forum

is Gmedia working on Android?

XmanXman Member
edited December 11 in Plugins
I used Gmedia plugin years ago and it worked well.
It seems the new android has changed to the photo picker, and the apis it used are from AppCompatActivity, is it possible implement the functions in Gmedia plugin?

https://developer.android.com/training/data-storage/shared/photopicker#java

Likes: MoKaLux

+1 -1 (+1 / -0 )Share on Facebook

Comments

  • MoKaLuxMoKaLux Member
    edited December 11
    hi Xman, I updated one of my app using Gmedia not long ago.
    There is a button where you can select an image from your android.

    Gmedia opens the photo picker just fine, the issue I have is before you could pick an image from any folder but now with new android only the photo folder is accessible

    EDIT: I can open any images from any folder just fine

    Here is some code (unformatted because of forum code formatting issue):
    btnloadtile:addEventListener("clicked", function() -- load external tile
    local function mediareceive(e)
    if self:isValidTexture(e.path) then
    local tempbmp = Bitmap.new(Texture.new(e.path, false))
    self.w, self.h = tempbmp:getWidth(), tempbmp:getHeight()
    if self.w == self.h and self.w <= 128 then
    g_currtexpath = e.path
    g_tilesize = self.w
    mySavePrefs(g_configfilepath)
    self:goToScene("tile")
    else
    local alertdialogwarnings = AlertDialog.new(
    "!!SIZE ERROR!!",
    "TILE,
    "OK")
    alertdialogwarnings:show()
    end
    mediamanager:removeEventListener(Event.MEDIA_RECEIVE, mediareceive)
    end
    end
    if g_isextrawarnings then
    alertdialogextrawarnings:addEventListener(Event.COMPLETE, function(e)
    mediamanager:getPicture() -- opens file explorer
    mediamanager:addEventListener(Event.MEDIA_RECEIVE, mediareceive)
    end)
    alertdialogextrawarnings:show()
    else
    mediamanager:getPicture() -- opens file explorer
    mediamanager:addEventListener(Event.MEDIA_RECEIVE, mediareceive)
    end
    end)

    This is Gideros 2024.11.1
    my growING GIDEROS github repositories: https://github.com/mokalux?tab=repositories
  • XmanXman Member
    edited December 12
    @MoKaLux thanks for your reply.

    The plugin I used was very very old, I updated to the new one, it always failed to request the permission, I removed it changed the function like this
    public static void getPicture() { // OK
    getPictureFunction();
    }
    Although it does not use the photo picker as google suggested, it works now.

    But I still can not get the take a photo from camera function work.
  • yes you are right something has changed with the way andoid handles the camera.

    I can take a picture but it won't show up in my app.

    The difference now is you need to click ok to validate the picture you have taken.

    This part in gmedia needs to be revisited in Gideros. I will try to have a look but no promise at all from me :|

    Here is the original wiki example https://wiki.gideros.rocks/index.php/Media_Plugin
    my growING GIDEROS github repositories: https://github.com/mokalux?tab=repositories
  • XmanXman Member
    I have modified the plugin to make it work for select image and take photo.
    It works well on my phone with android os LineageOS 21, but it maybe failed on some devices. Here is my code.

    the steps to take full image using FileProvider
    https://stackoverflow.com/questions/38200282/android-os-fileuriexposedexception-file-storage-emulated-0-test-txt-exposed
  • XmanXman Member
    I have modified the plugin to make it work for select image and take photo.
    It works well on my phone with android os LineageOS 21, but it maybe failed on some devices. Here is my code.

    the steps to take full image using FileProvider
    https://stackoverflow.com/questions/38200282/android-os-fileuriexposedexception-file-storage-emulated-0-test-txt-exposed
  • XmanXman Member
    I have modified the plugin to make it work for select image and take photo.
    It works well on my phone with android os LineageOS 21, but it maybe failed on some devices. Here is my code.

    the steps to take full image using FileProvider
    https://stackoverflow.com/questions/38200282/android-os-fileuriexposedexception-file-storage-emulated-0-test-txt-exposed
  • XmanXman Member
    I have modified the plugin to make it work for select image and take photo.
    It works well on my phone with android os LineageOS 21, but it maybe failed on some devices. Here is my code.

    the steps to take full image using FileProvider
    https://stackoverflow.com/questions/38200282/android-os-fileuriexposedexception-file-storage-emulated-0-test-txt-exposed
  • XmanXman Member
    I have modified the plugin to make it work for select image and take photo.
    It works well on my phone with android os LineageOS 21, but it maybe failed on some devices. Here is my code.

    the steps to take full image using FileProvider
    https://stackoverflow.com/questions/38200282/android-os-fileuriexposedexception-file-storage-emulated-0-test-txt-exposed
  • XmanXman Member
    sorry for stuck connection, I posted it multiple times.
    here is the code.
    zip
    zip
    GMedia.java.zip
    5K
  • XmanXman Member
    updated code.
    zip
    zip
    GMedia.java.zip
    5K

    Likes: pie

    +1 -1 (+1 / -0 )Share on Facebook
  • XmanXman Member
    edited December 13
    load Some kinds of images will just make the screen black, it is the limitation of the engine itself, it can not show large textures.
    It's a bug of engine.

    Likes: MoKaLux, pie

    +1 -1 (+2 / -0 )Share on Facebook
  • I am making some progress with android gmedia but slow progress :p
    Some breaking changes happened with android 11 and up, for example the app folder has either been removed or is now encrypted. I may be able to save to android pictures folder?
    Doing some more tests tinkering with some gideros java files and android studio :s
    my growING GIDEROS github repositories: https://github.com/mokalux?tab=repositories
  • MoKaLuxMoKaLux Member
    edited 4:26AM
    Conclusion on my research on GMedia and Android :# :
    - my results are here: https://wiki.gideros.rocks/index.php/CPlusPlus_for_Gideros_Studio_Help#CANNOT_ACCESS_android.2Fdata.2Fpackagename.2Ffiles.2F_on_Android_29.2B

    So Android 29+ implements new granular file access with a set of new permissions which are not yet implemented in Gideros:
    - android.permission.READ_MEDIA_IMAGES
    - android.permission.READ_MEDIA_VIDEO
    - android.permission.READ_MEDIA_VISUAL_USER_SELECTED

    thus accessing external files is not possible targeting android 29+.

    What works:
    - mediamanager:isCameraAvailable
    - mediamanager:postPicture
    - mediamanager:takePicture (kind of)

    What doesn't work:
    - mediamanager:getPicture
    - mediamanager:playVideo
    - mediamanager:takeScreenshot

    In order to use latest Android privacy stuff we need to add the new PickVisualMediaRequest to GiderosApplication.java but this is out of my league :p
        // Register ActivityResult handler
        // GetContent creates an ActivityResultLauncher to let you pass
        // in the mime type you want to let the user select
        public static ActivityResultLauncher pickMedia = registerForActivityResult(
                new ActivityResultContracts.PickVisualMedia(),
                (uri) -> {
                    // Callback is invoked after the user selects a media item or closes the photo picker
                    if (uri != null) {
                        Log.d("PhotoPicker", "Selected URI: " + uri);
                    } else {
                        Log.d("PhotoPicker", "No media selected");
                    }
                });
     
        private static ActivityResultLauncher registerForActivityResult(
                ActivityResultContracts.PickVisualMedia getContent, ActivityResultCallback activityResultCallback) {
            Log.d("XXX", "XXX ActivityResultLauncher");
            return null;
        }
            GMedia.pickMedia.launch(new PickVisualMediaRequest.Builder()
                    .setMediaType(ActivityResultContracts.PickVisualMedia.ImageOnly.INSTANCE)
                    .build()); // java.lang.NullPointerException: Attempt to invoke virtual method
                               //    'void androidx.activity.result.ActivityResultLauncher.launch(java.lang.Object)'
                               //    on a null object reference
    Viva Gideros :)
    my growING GIDEROS github repositories: https://github.com/mokalux?tab=repositories
Sign In or Register to comment.