B4A Library Device Administrator library

Status
Not open for further replies.

moster67

Expert
Licensed User
Longtime User
Using the role of the Device Administrator, is this the way that automation tools, such as Tasker, works?
 

moster67

Expert
Licensed User
Longtime User
I would like to find out how automation apps such as Tasker work and how they do things and I thought this library might matter.
I will open a separate question.
 

ykucuk

Well-Known Member
Licensed User
Longtime User
Hi,
I downloaded example project. I did set read-only the XML file in the Res folder.

Tried 3 different devices but doesn't work. Not even log or any error.

I attached a screenshot with unfiltered logs.

Any help?
 

Attachments

  • Screen Shot 2017-09-11 at 12.02.58.png
    100.8 KB · Views: 473

Erel

B4X founder
Staff member
Licensed User
Longtime User
I did set read-only the XML file in the Res folder.
That is not needed. It creates the XML with CreateResource command.

I attached a screenshot with unfiltered logs.
It is always better to post text instead of screenshots. You can right click to copy.

There is nothing relevant in the logs.
 

ykucuk

Well-Known Member
Licensed User
Longtime User
That is not needed. It creates the XML with CreateResource command.



It is always better to post text instead of screenshots. You can right click to copy.

There is nothing relevant in the logs.

It gives error "file not found:deviceadmin.XML" if don't set read only.

is there way copy all log because its like listbox and can copy line by line.

I added my project file. Already tried 4 different devices and cant figure out. I need administrator right.

could you check when you have time.
 

Attachments

  • AdminExample.zip
    406.4 KB · Views: 524

Xenno

Member
Licensed User
Please, help. I followed the steps but keeps failing. No device administration dialog appear on calling "Enable".

The log shows:
B4X:
Unable to retrieve device policy ComponentInfo{com.sample.test/anywheresoftware.b4a.objects.AdminManager$AdminReceiver}

In manifest code:
B4X:
AddApplicationText(<receiver android:name="anywheresoftware.b4a.objects.AdminReceiver"
...

The device_admin.xml exists in res/xml

B4A 6.80


TIA
 

Xenno

Member
Licensed User
Here is the manifest code:
B4X:
'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: https://www.b4x.com/forum/showthread.php?p=78136
AddManifestText(
<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="19"/>
<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.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>)

CreateResource(xml, device_admin.xml,
<device-admin xmlns:android="http://schemas.android.com/apk/res/android">
  <uses-policies>
  <limit-password />
  <reset-password />
  <force-lock />
  </uses-policies>
</device-admin>
)

Here's the code in main activity:
B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

    Public AdmMgr As AdminManager
End Sub

...

Sub cbEnable_CheckedChange(Checked As Boolean)
    If (Checked) Then      
        If Not(AdmMgr.Enabled) Then
            AdmMgr.Enable("Device Administration for this app is required.")
            If Not(AdmMgr.Enabled) Then
                cbEnable.Checked = False
            End If
        End If
    End If
End Sub
 
Last edited:

noeleon

Active Member
Licensed User
Longtime User
r.RunMethod4("setCameraDisabled", Array As Object(cm, True), _
Array As String("android.content.ComponentName", "java.lang.boolean") 'change to False to enable camera
Can't enable the camera if it was disabled by another admin app. How do i check for this?

And how to launch the Device Administrators activity in android settings?
Thanks.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…