Android Question Camera permission [solved]

Didier9

Well-Known Member
Licensed User
Longtime 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:
B4X:
    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:
B4X:
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...
 

BillMeyer

Well-Known Member
Licensed User
Longtime User
I don't see the camera permission in your manifest.

I guess this is your problem.
 
Upvote 0

Didier9

Well-Known Member
Licensed User
Longtime User
I don't see the camera permission in your manifest.

I guess this is your problem.

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:
B4X:
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)
)
 
Upvote 0

Didier9

Well-Known Member
Licensed User
Longtime 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:
Upvote 0
Top