Android Question Camera Permission issue with Android Ver 13 SDK 33

GeoffT660

Active Member
Licensed User
Longtime User
I'm trying to get the camera functionality to work on a new Tera P166 device with integrated scanner but the camera won't open and reports an error
B4X:
java.lang.SecurityException: com.bizmoblid was not granted this permission: android.permission.WRITE_SETTINGS.
. if I follow Erel's example from post https://www.b4x.com/android/forum/threads/permission-write_settings.94311/ I get the setting screen and can toggle to On but then I get this error
B4X:
ava.lang.IllegalArgumentException: You cannot keep your settings in the secure settings.
when running the code
B4X:
camera.OpenCamera(id)
in CamEx2. I've never had any issue accessing the camera on any other of the many devices that run my application. Please let me know if there is a solution for this issue. Thanks!
 

Alexander Stolte

Expert
Licensed User
Longtime User
Try the following manifest code:
B4X:
AddManifestText(<uses-permission android:name="android.permission.WRITE_SETTINGS" />)
AddActivityText(Main,
<activity android:name=".permission.WriteSettingsPermissionActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
)
 
Upvote 0

GeoffT660

Active Member
Licensed User
Longtime User
Thanks Alex! This now gives me an error while compiling.
B4X:
Linking resources    Error
AndroidManifest.xml:101: error: unexpected element <activity> found in <manifest><application><activity>.
This old app has not been converted to B4x pages.
 
Upvote 0

GeoffT660

Active Member
Licensed User
Longtime User
I think I need this permission because the Error message says I need this permission when I call
B4X:
camera.OpenCamera(id)
in the OpenCamera function of CamEx2. The error also occurs in the Camera2 example. Works on the previous version of the Tera P166 device running Android 9 but not on the new device running Android 13. Should I check with the manufacturer for this Java documentation? The full error message is:
B4X:
Error occurred on line: 61 (CamEx2)
java.lang.SecurityException: com.bizmoblid was not granted  this permission: android.permission.WRITE_SETTINGS.
    at android.os.Parcel.createExceptionOrNull(Parcel.java:3011)
    at android.os.Parcel.createException(Parcel.java:2995)
    at android.os.Parcel.readException(Parcel.java:2978)
    at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:190)
    at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:142)
    at android.content.ContentProviderProxy.call(ContentProviderNative.java:732)
    at android.provider.Settings$NameValueCache.putStringForUser(Settings.java:3012)
    at android.provider.Settings$System.putStringForUser(Settings.java:3817)
    at android.provider.Settings$System.putStringForUser(Settings.java:3800)
    at android.provider.Settings$System.putStringForUser(Settings.java:3794)
    at android.provider.Settings$System.putIntForUser(Settings.java:3918)
    at android.provider.Settings$System.putInt(Settings.java:3911)
    at android.hardware.camera2.CameraManager.openCamera(CameraManager.java:853)
    at anywheresoftware.b4a.objects.Camera2.OpenCamera(Camera2.java:114)
    at com.bizmoblid.camex2$ResumableSub_OpenCamera.resume(camex2.java:577)
    at com.bizmoblid.camex2._opencamera(camex2.java:490)
    at com.bizmoblid.frmidscan$ResumableSub_OpenCamera.resume(frmidscan.java:19432)
    at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resumeAsUserSub(DebugResumableSub.java:48)
    at anywheresoftware.b4a.shell.Shell.runGoodChain(Shell.java:475)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:293)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:157)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:201)
    at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resume(DebugResumableSub.java:43)
    at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:275)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:150)
    at anywheresoftware.b4a.BA$2.run(BA.java:395)
    at android.os.Handler.handleCallback(Handler.java:942)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loopOnce(Looper.java:201)
    at android.os.Looper.loop(Looper.java:288)
    at android.app.ActivityThread.main(ActivityThread.java:7918)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:942)
Caused by: android.os.RemoteException: Remote stack trace:
    at android.provider.Settings.isCallingPackageAllowedToPerformAppOpsProtectedOperation(Settings.java:18660)
    at android.provider.Settings.checkAndNoteWriteSettingsOperation(Settings.java:18548)
    at com.android.providers.settings.SettingsProvider.mutateSystemSetting(SettingsProvider.java:1890)
    at com.android.providers.settings.SettingsProvider.insertSystemSetting(SettingsProvider.java:1856)
    at com.android.providers.settings.SettingsProvider.call(SettingsProvider.java:468)
If I try your suggestion in this post: https://www.b4x.com/android/forum/threads/permission-write_settings.94311/ I get the Modify System Settings screen
SystemSettings.jpg
and can toggle the setting to On but then the error message changes to:
B4X:
Error occurred on line: 61 (CamEx2)
java.lang.IllegalArgumentException: You cannot keep your settings in the secure settings.
    at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:172)
    at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:142)
    at android.content.ContentProviderProxy.call(ContentProviderNative.java:732)
    at android.provider.Settings$NameValueCache.putStringForUser(Settings.java:3012)
    at android.provider.Settings$System.putStringForUser(Settings.java:3817)
    at android.provider.Settings$System.putStringForUser(Settings.java:3800)
    at android.provider.Settings$System.putStringForUser(Settings.java:3794)
    at android.provider.Settings$System.putIntForUser(Settings.java:3918)
    at android.provider.Settings$System.putInt(Settings.java:3911)
    at android.hardware.camera2.CameraManager.openCamera(CameraManager.java:853)
    at anywheresoftware.b4a.objects.Camera2.OpenCamera(Camera2.java:114)
    at com.bizmoblid.camex2$ResumableSub_OpenCamera.resume(camex2.java:577)
    at com.bizmoblid.camex2._opencamera(camex2.java:490)
    at com.bizmoblid.frmidscan$ResumableSub_OpenCamera.resume(frmidscan.java:19432)
    at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resumeAsUserSub(DebugResumableSub.java:48)
    at anywheresoftware.b4a.shell.Shell.runGoodChain(Shell.java:475)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:293)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:157)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:201)
    at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resume(DebugResumableSub.java:43)
    at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:275)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:150)
    at anywheresoftware.b4a.BA$2.run(BA.java:395)
    at android.os.Handler.handleCallback(Handler.java:942)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loopOnce(Looper.java:201)
    at android.os.Looper.loop(Looper.java:288)
    at android.app.ActivityThread.main(ActivityThread.java:7918)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)

Not sure what else I can do to make the camera work on this device.
 
Upvote 0
Top