Search code examples
genexus-sd

Camera.TakePhoto () produces security exception in Android application generated with GX15 U12 (this did not happen until GX15 U11)


We are generating an android code with Genexus 15 U12 for a panel where we take a picture. When the panel is open the application stops with a "security exception" error with error line "android.permission.CAMERA". Application never requests permission to access the camera.

The AndroidManifest.xml file has this permission.

Is there anything else we need to do to request permission before entering the panel where we use the api Camera.TakePhoto ()?

On logcat this error is shown

10-12 23:42:21.376: E/AndroidRuntime(2736): Caused by: java.lang.SecurityException: Permission Denial: starting Intent { act=android.media.action.IMAGE_CAPTURE flg=0x80003 cmp=com.android.camera/.Camera clip={text/uri-list U:content://ec.com.inalambrik.routik.file_provider/external/Android/data/ec.com.inalambrik.routik/files/Pictures/2018-10-12--23-42-21-3331914767202.jpg} (has extras) } from ProcessRecord{c7a0f9a 2736:ec.com.inalambrik.routik/u0a66} (pid=2736, uid=10066) with revoked permission android.permission.CAMERA

This behavior did not occur until GX15 U11


Solution

  • On external object, I create the following method:

    public static String askForPermission(){
        try{            
            Log.d("PERMISSION", "askForPermission" );
            // Context context = MyApplication.getInstance();
            Context context = MyApplication.getAppContext();        
    
            // Launch Settings screen.
            /*Intent intent = new Intent();
            intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
            Uri uri = Uri.fromParts("package", context.getPackageName(), null);
            intent.setData(uri);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(intent);*/
    
            Intent intent = new Intent(context, InalambrikRequestPermissionActivity.class);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(intent);
    
            return "";
        }catch(Exception e){
            e.printStackTrace();
            return "Por favor intentar nuevamente. Si el problema persiste, debe ir Ajustes del dispositivo > Aplicaciones > Ir a detalles de la aplicación > Habilitar los permisos manualmente.";
        }
    }