简体   繁体   中英

Kiosk mode in NativeScript for Android App

From past few days, I am trying to implement kiosk mode (Locked app) in NativeScript with Angular for Android App.

I have tried it directly but unable to handle all the buttons in Android like Home and Recent Apps buttons. I am able to handle Back and Volume up and down buttons.

The other way, I tried is creating my own Plugin using Android Native but I was unable to do so.

There are two options for Kiosk mode in Android Native. One is Screen Pinning (Programmatically) and the other is using COSU in Android (Which is not my requirement because I cannot set the app as Device Owner for 1000's of devices).

So, Can anyone share their knowledge of using Screen Pinning in Android and Creating the plugin for that in NativeScript and example Code in NativeScript.

Thanks In Advance!

Below is my Java code for Android Native to implement Screen Pinning

package org.nativescript.sdoddapaneni.kioskmodeplugin;

import android.app.ActivityManager;
import android.os.Build;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class LoginActivity extends AppCompatActivity {

    private Button pinAppBtn;
    private Button unpinAppBtn;
    private ActivityManager am;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);

        pinAppBtn = (Button) findViewById(R.id.pin_app);
        unpinAppBtn = (Button) findViewById(R.id.unpin_app);

        am = (ActivityManager) getSystemService(ACTIVITY_SERVICE);

        pinAppBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                pin();
            }
        });
        unpinAppBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                unpin();
            }
        });

    }

    public void unpin() {
        if (am.isInLockTaskMode()) {
            stopLockTask();
        } else {
            Toast.makeText(this, "Application already unpinned !", Toast.LENGTH_SHORT).show();
        }
    }

    public void pin() {
        startLockTask();
    }
}

Here is how you will extend the default activity in NativeScript. FYI, With v4.x NativeScript still uses activity , staring 5.x they introduced AppCompatActivity which is expected to be released in another few days.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM