Create customize app permission for upload image in native application

0
Hi Experts, Hope you are doing good,   I want to show customize app permissionin for native mobile application with options ( Always Allow, Allow Limited Access/Allow this time, and Don't Allow)  on click of upload image widget. How can i do this?   Thanks for support          
asked
3 answers
0

Hello KBL,

 

Have you already looked at this documentation of Mendix : 

https://docs.mendix.com/refguide/mobile/using-mobile-capabilities/generic-permission-action/

 

It is explaining step by step how to ask for permissions with a native application.

You just have to find the right one for your use case and after it functions like how you used to manage your permissions on your phone.

 

Hope this helps,

 

Good luck!

answered
0

Hi KBL,

If you are using your own custom image upload widget then you have to take the permission inside the widget code using JS/React code.

answered
0

Hi KBL,

Go to Studio Pro > JavaScript Actions > New Action

 

Example Code:

import { Upload, Platform } from "react-native";

 

export async function CheckAndRequestUplaod() {

    if (Platform.OS === "android") {

        const granted = await Upload.check(

            Upload.PERMISSIONS.READ_EXTERNAL_STORAGE

        );

 

        if (!granted) {

            const result = await Upload.request(

                Upload.PERMISSIONS.READ_EXTERNAL_STORAGE,

                {

                    title: "Image Access Permission",

                    message:

                        "This app needs access to your gallery to upload images. Choose how you'd like to proceed.",

                    buttonPositive: "Allow This Time",

                    buttonNegative: "Don't Allow",

                    buttonNeutral: "Always Allow",

                }

            );

 

            return result; // result = 'granted', 'denied', or 'never_ask_again'

        } else {

            return "granted";

        }

    } else {

        // iOS automatically handles permissions on image picker usage

        return "granted";

    }

}

  1. Call CheckAndRequestUplaod
  2. Use a Decision split:
    • If result = granted, show the image picker.
    • Else, show a message like “Permission denied. Cannot upload image.
  3. And finally Use the "Take Picture" or "Image Picker" widget from the Native Mobile Resources module to handle actual image uploading after permission is granted

Please follow these steps based on your requirement and modify the JavaScript accordingly. I hope this is helpful to you

 

Thanks

answered