Android Question Probelm trying to disable/enable camera

Jmu5667

Well-Known Member
Licensed User
Longtime User
Hi

I am trying to disable/enable the camera, have looked and experimented with the administrator lib and tried using the suggested reflection method. I get the following errors -

[log]
Installing file.
PackageAdded: package:com.is.vitllinkAPF
** Activity (main) Create, isFirst = true **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Resume **
(Main, 331) Panel.LoadLayout should only be called after the panel was added to its parent. (warning #1001)
(Main, 331) Panel.LoadLayout should only be called after the panel was added to its parent. (warning #1001)
No partial wakelock.
No partial wakelock.
** Service (wifi_manager) Create **
** Service (wifi_manager) Create **
** Service (wifi_manager) Start **
** Service (wifi_manager) Start **
** Activity (main) Pause, UserClosed = false **
** Activity (main) Pause, UserClosed = false **
No partial wakelock.
WakeLock already held.
No partial wakelock.
WakeLock already held.
** Service (service_manager) Create **
** Service (service_manager) Create **
** Service (service_manager) Start **
** Service (service_manager) Start **
11:59:19 Starting Scan ...
11:59:19 Starting Scan ...
11:59:19 Next WiFi Update @ 12:00:19
11:59:19 Next WiFi Update @ 12:00:19
11:59:29 Scan Finished...
11:59:29 Scan Finished...
Mac 00115061E0D4 RSSI -67
Mac 00115061E0D4 RSSI -67
functions_set_camera_state (B4A line: 77)
r.RunMethod4("setCameraDisabled", Array As Object(cm, pState), Array As String("android.content.ComponentName", "java.lang.boolean"))
functions_set_camera_state (B4A line: 77)
r.RunMethod4("setCameraDisabled", Array As Object(cm, pState), Array As String("android.content.ComponentName", "java.lang.boolean"))
java.lang.SecurityException: No active admin ComponentInfo{com.is.vitllinkAPF/anywheresoftware.b4a.objects.AdminManager$AdminReceiver}
at android.os.Parcel.readException(Parcel.java:1434)
at android.os.Parcel.readException(Parcel.java:1388)
at android.app.admin.IDevicePolicyManager$Stub$Proxy.setCameraDisabled(IDevicePolicyManager.java:3334)
at android.app.admin.DevicePolicyManager.setCameraDisabled(DevicePolicyManager.java:1845)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.agraham.reflection.Reflection.runmethod(Reflection.java:216)
at anywheresoftware.b4a.agraham.reflection.Reflection.RunMethod4(Reflection.java:857)
at com.is.vitllinkAPF.functions._set_camera_state(functions.java:291)
at com.is.vitllinkAPF.functions._execute_event(functions.java:46)
at com.is.vitllinkAPF.functions._process_networks(functions.java:217)
at com.is.vitllinkAPF.wifi_manager._tmrwifiscanfornetworks_tick(wifi_manager.java:454)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:170)
at anywheresoftware.b4a.objects.Timer$TickTack.run(Timer.java:105)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:5751)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1083)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:850)
at dalvik.system.NativeStart.main(Native Method)
java.lang.SecurityException: No active admin ComponentInfo{com.is.vitllinkAPF/anywheresoftware.b4a.objects.AdminManager$AdminReceiver}
at android.os.Parcel.readException(Parcel.java:1434)
at android.os.Parcel.readException(Parcel.java:1388)
at android.app.admin.IDevicePolicyManager$Stub$Proxy.setCameraDisabled(IDevicePolicyManager.java:3334)
at android.app.admin.DevicePolicyManager.setCameraDisabled(DevicePolicyManager.java:1845)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.agraham.reflection.Reflection.runmethod(Reflection.java:216)
at anywheresoftware.b4a.agraham.reflection.Reflection.RunMethod4(Reflection.java:857)
at com.is.vitllinkAPF.functions._set_camera_state(functions.java:291)
at com.is.vitllinkAPF.functions._execute_event(functions.java:46)
at com.is.vitllinkAPF.functions._process_networks(functions.java:217)
at com.is.vitllinkAPF.wifi_manager._tmrwifiscanfornetworks_tick(wifi_manager.java:454)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:170)
at anywheresoftware.b4a.objects.Timer$TickTack.run(Timer.java:105)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:5751)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1083)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:850)
at dalvik.system.NativeStart.main(Native Method)

[/log]

[manifest]
'This code will be applied to the manifest file during compilation.
'You do not need to modify it in most cases.
'See this link for for more information: http://www.b4x.com/forum/showthread.php?p=78136
AddManifestText(
<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="14"/>
<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.
AddApplicationText(<receiver android:name="anywheresoftware.b4a.objects.AdminManager$AdminReceiver"
android:permission="android.permission.BIND_DEVICE_ADMIN">
<meta-data android:name="android.app.device_admin"
android:resource="@xml/device_admin" />
<intent-filter>
<action android:name="android.app.action.DEVICE_ADMIN_ENABLED" />
</intent-filter>
</receiver>)

[/manifest]

All help would be appreciated

Regards


John.
 

Jmu5667

Well-Known Member
Licensed User
Longtime User
Hi Erel

Thanks for that, sorted it out. Needed to modify the xml res file. Long shot, is there any way to set this without the user(phone owner) disabling the app permissions to disable the camera, in the security section on the phone settings.

Our customer would love this feature, so their employees phone auto disable the camera when then enter certain areas of their building. We have this working now here in the office but you can simply disable the app privileges via the settings :(

Thanks again for your help.

Regards

John.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Our customer would love this feature, so their employees phone auto disable the camera when then enter certain areas of their building. We have this working now here in the office but you can simply disable the app privileges via the settings
This is how Android works. The user can always disable the administrator app.

You can however send a notification to an online server when the user disabled the app.
 
Upvote 0
Top