How to use Android-L preview Task Locking?

本小妞迷上赌 提交于 2019-12-29 05:23:45

问题


Has anyone got task locking working in Android L? Could they share some details on how it works? I have seen the instructions below, but struggling to understand this.

At the moment I have made an App that I would like to run in kiosk mode. I have looked at making it a launcher App or using Surelock but the new task locking looks like it will be the best option in future.

I need to create a userdebug build of Android L? I have not built Android from source before, I started looking at making a build but I don't think the source for Android-L is available yet?

To set up a device owner, follow these steps:

Attach a device running an Android userdebug build to your development machine.
Install your device owner app.
Create a device_owner.xml file and save it to the /data/system directory on the device.

$ adb root
$ adb shell stop
$ rm /tmp/device_owner.xml
$ echo "<?xml version='1.0' encoding='utf-8' standalone='yes' ?>">> /tmp/device_owner.xml
$ echo "<device-owner package=\"<your_device_owner_package>\"name=\"*<your_organization_name>\" />" >> /tmp/device_owner.xml
$ adb push /tmp/device_owner.xml /data/system/device_owner.xml
$ adb reboot

https://developer.android.com/preview/api-overview.html

Edit: More info

I tried rooting my device (Nexus 7) running the Android-L preview. I then put a device_owner.xml with my package name in data/system/. But it still does not work, islockTaskPermited() return false, and calling startLockTask() does nothing.


回答1:


Taking Below Snip from Task Locking API

It is clear that startLockTask() api will be hv effect if device_owner.xml is present .

How do i check if my app is device owner ?

When you app is device owner , you app is Device Administrator option will be checked and checkbox will be gray out hence will not allow u to untick the checkbox.

You need to give system right while pushing device_owner.xml

Follow below steps :

  1. Create device_owner.xml [make sure the app will be present before u push device_owner.xml ]
  2. Navigate to path in terminal where device_owner is present
  3. adb push device_owner.xml /sdcard/
  4. adb shell
  5. su
  6. cp /sdcard/device_owner.xml /data/system/
  7. cd /data/system/
  8. chown system:system device_owner.xml
  9. reboot



回答2:


Make a file device_owner.xml using below content, replace appropriate package name

<?xml version='1.0' encoding='utf-8' standalone='yes' ?>
<device-owner package="com.your.packagename" name="Yourname" />

adb push device_owner.xml /data/system/device_owner.xml Reboot device.

from com.your.packagename app call

startLockTask(); 

from your activity

Even if you do not have userdebug, you can test it by calling startLockTask, without pushing any file



来源:https://stackoverflow.com/questions/26358689/how-to-use-android-l-preview-task-locking

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!