Kiosk mode in NativeScript for Android App

那年仲夏 提交于 2019-12-09 20:08:39

问题


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();
    }
}

回答1:


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.



来源:https://stackoverflow.com/questions/53014879/kiosk-mode-in-nativescript-for-android-app

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