1.0.0 • Published 3 years ago

cordova-plugin-launcher-cc v1.0.0

Weekly downloads
6
License
ISC
Repository
github
Last release
3 years ago

LockTask

A Cordova plugin that provides access to Android’s screen pinning APIs.

Installation

LockTask will only work on Android devices for apps targeting Lollipop (API 21) or above.

Navigate to your project root and run:

cordova plugin add https://github.com/oddmouse/cordova-plugin-locktask.git

Usage

startLockTask

window.plugins.locktask.startLockTask(successCallback, errorCallback, className);

stopLockTask

window.plugins.locktask.stopLockTask(successCallback, errorCallback);

Device admin

If the app is not set up as the device owner, the user will have to accept a prompt when startLockTask is called. The user will also be able to unpin the screen with a navigation button combination. With device owner set, there is no prompt and only the app itself can unpin the screen.

IMPORTANT: Once set, you cannot unset device owner or uninstall the app without factory resetting the device.

There are several ways to set device owner but this is the method that worked for me.

  1. Enable Developer options on the device by repeatedly tapping Build number under Settings > About Tablet.

  2. Check the USB debugging option under Settings > Developer options.

  3. Add a device admin sub class of DeviceAdminReceiver next to the project source. (e.g., platforms/android/src/com/example/package/ExampleAppAdmin.java)

    package com.example.package;
    import android.app.admin.DeviceAdminReceiver;
    public class ExampleAppAdmin extends DeviceAdminReceiver {
      // Some code here if you want but not necessary
    }
  4. Add the receiver to AndroidManifest.xml directly below </activity>, giving it the same name as the DeviceAdminReceiver sub class.

    <receiver android:label="@string/app_name" android:name="ExampleAppAdmin" 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>
  5. Declare security policies in res/xml/device_admin.xml

    <device-admin xmlns:android="http://schemas.android.com/apk/res/android">
      <uses-policies>
        <limit-password />
        <watch-login />
        <reset-password />
        <force-lock />
        <wipe-data />
        <expire-password />
        <encrypted-storage />
        <disable-camera />
      </uses-policies>
    </device-admin>
  6. Connect device via USB.

  7. Install the app to the device.

  8. Use Android Debug Bridge and Device Policy Manager to set device owner.

    adb shell
    dpm set-device-owner com.example.package/.ExampleAppAdmin
  9. All done!