1. *** New version of B4J is available ***
    B4J v7.8
    Dismiss Notice

Android Question Camera permission [solved]

Discussion in 'Android Questions' started by Didier9, Aug 24, 2019.

  1. Didier9

    Didier9 Active Member Licensed User

    Now the camera...
    It's going to be a long week-end!

    When I try to fetch the camera (and storage) permissions with this:
    Code:
    For Each permission As String In Array( rp.PERMISSION_READ_EXTERNAL_STORAGE, rp.PERMISSION_CAMERA )
            rp.CheckAndRequest( permission )
            
    Wait For Activity_PermissionResult( permission As String, Result As Boolean )
            
    If Result = False Then
                
    ToastMessageShow"No storage or camera permission!"True )
                
    Activity.Finish
                
    Return
            
    End If
        
    Next
    It fails with the camera (but works with the storage...)
    I tried to change the order, same thing.
    Here is the manifest:
    Code:
    AddManifestText(
    <uses-sdk android:minSdkVersion=
    "21" android:targetSdkVersion="26"/>
    <supports-screens android:largeScreens=
    "true"
        android:normalScreens=
    "true"
        android:smallScreens=
    "true"
        android:anyDensity=
    "true"/>)
    SetApplicationAttribute(android:icon, 
    "@drawable/icon")
    SetApplicationAttribute(android:
    label"$LABEL$")
    SetApplicationAttribute(android:theme, 
    "@android:style/Theme.Holo")
    'SetApplicationAttribute(android:theme, "@android:style/Widget.Holo.Light.ProgressBar.Small.Inverse")
    'End of default text.
    SetActivityAttribute(EditLog, android:windowSoftInputMode, adjustResize|stateHidden)
    AddManifestText(<uses-permission
    android:name=
    "android.permission.WRITE_EXTERNAL_STORAGE"
    android:maxSdkVersion=
    "18" />
    )
    AddPermission(android.permission.RECORD_AUDIO)
    AddApplicationText(
      <provider
      android:name=
    "android.support.v4.content.FileProvider"
      android:authorities=
    "$PACKAGE$.provider"
      android:exported=
    "false"
      android:grantUriPermissions=
    "true">
      <meta-data
      android:name=
    "android.support.FILE_PROVIDER_PATHS"
      android:resource=
    "@xml/provider_paths"/>
      </provider>
    )
    CreateResource(xml, provider_paths,
       <files-
    path name="name" path="shared" />
    )
    The Camera2 example does work though on the same phone (Moto-X 4, Android 9).
    Actually none of my devices get the camera permission, even the older ones (Android 6) which don't even need it...
     
  2. BillMeyer

    BillMeyer Active Member Licensed User

    I don't see the camera permission in your manifest.

    I guess this is your problem.
     
  3. Didier9

    Didier9 Active Member Licensed User

    I had one that I was using with Android 6. The Camera example from Erel does not have it.
    I added it just to make sure, made no difference.
    Here what is in Erel's example:
    Code:
    AddManifestText(
    <uses-sdk android:minSdkVersion=
    "21" android:targetSdkVersion="26"/>
    <supports-screens android:largeScreens=
    "true"
        android:normalScreens=
    "true"
        android:smallScreens=
    "true"
        android:anyDensity=
    "true"/>)
    SetApplicationAttribute(android:icon, 
    "@drawable/icon")
    SetApplicationAttribute(android:
    label"$LABEL$")
    'End of default text.
    AddPermission(android.permission.RECORD_AUDIO)
    )
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    Always start by clicking on Logs - List Permissions.
    You will see which permissions were detected by the compiler.

    Your handling of the external storage permission is wrong. Make sure to watch the runtime permissions video tutorial.
     
    BillMeyer likes this.
  5. Didier9

    Didier9 Active Member Licensed User

    Not sure what the problem was. For reference, I was using the camera intent, not the camera itself directly into my app.
    When using the camera intent, it is my understanding that a permission is not normally required, so that's why I was surprised my old app stopped working.

    I found this thread https://www.b4x.com/android/forum/threads/camera-intent-picture-and-video.107636/#content which was working fine on all my devices and I followed the way the intent is invoked, which was not that different from the way I was doing it before.

    In the process, I was able to actually clean up and simplify my app (eliminated an activity, but added a class...) so while it took MUCH longer than I anticipated (due to me chasing permissions...), I am happy.

    Anyhow, problem solved (don't need camera permission) but I am not sure why it failed in the first place.
     
    Last edited: Aug 25, 2019
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice