簡體   English   中英

Android的Kiosk模式

[英]Kiosk mode for android

我有一個混合應用程序寫在phonegap為Android平板電腦。 現在我希望平板電腦只顯示我的應用程序。 基本上我希望平板電腦始終處於僅運行我的應用程序的信息亭模式。 這樣所有按鈕都被禁用。 我在網上尋找解決方案,其中一個是使用“surelock”,但它沒有做到以上所有。 另一個選擇是編寫我自己的ROM,但是我找不到任何好的教程。 任何人都可以幫助我PLZ?

我做了很多研究,現在終於對我得到的東西感到滿意。

你基本上有兩個選擇:

  1. 創建自己的自定義ROM,這對我來說不是最好的解決方案。

  2. 使用各種黑客自定義平板電腦。

所以我將解釋第二個選項。

首先,您需要根設備。 有各種方法,但我更喜歡通過oneclick軟件生根。 對於中國平板電腦,您可以使用VROOT,對於更受歡迎的平板電腦,請使用Kingo root。

現在,您的設備已根植,我們可以擺脫頂部和底部的條形圖。

private void hideBar(){
    try
    {
        Process proc = Runtime.getRuntime().exec(new String[]{"su","-c","service call activity 42 s16 com.android.systemui"}); 
        proc.waitFor();
    }
    catch(Exception ex)
    {
        Toast.makeText(getApplicationContext(), ex.getMessage(), Toast.LENGTH_LONG).show();
        Log.e("ROOT ERROR", ex.getMessage());
    }
}

這將使頂部和底部條消失。 但是,您可能需要一種方法再次顯示條形圖。 為此您可以使用:

public void showBars(){
    try 
    {
        String command;
        command = "LD_LIBRARY_PATH=/vendor/lib:/system/lib am startservice -n com.android.systemui/.SystemUIService";
        String[] envp = null;
        Process proc = Runtime.getRuntime().exec(new String[] { "su", "-c", command }, envp);
        proc.waitFor();
    } 
    catch(Exception ex)
    {
        Toast.makeText(context.getApplicationContext(), ex.getMessage(), Toast.LENGTH_LONG).show();
    }
}

好的,我們還有,剩下的就是讓你的應用程序在啟動時啟動。 為此你可以找到許多教程,只是谷歌。

使用Android L-release(Lollipop),有一個稱為固定的功能,幾乎相當於Kiosk模式。 這是一個解釋如何設置的鏈接。

我相信Apple首先在iOS中推出了這款產品。 即使OP沒有問過,我也提供了iOS的詳細信息:

Android: http//www.cnet.com/how-to/ho-to-pin-apps-in-android-5-lollipop/

iOS: http//www.webascender.com/Blog/ID/447/How-to-Setup-Kiosk-Mode-Lock-Your-iPad-to-Just-One-App#.VzrO2ZN95E5

我認為有一種替代解決方案,無需支持設備。 我的老板讓我避免生根,所以經過一些研究后我才開始解決這個問題。 結果,沒有完成任何黑客攻擊,系統密鑰仍然存在,但用戶無法離開應用程序並啟動另一個應用程序。 所以,我做了以下步驟。

1.通過編輯清單設置全屏主題,沒有TitleBarActionBar用於相應的Activity ,如下所示:

<application
    ...
    android:theme="android:Theme.Holo.NoActionBar.Fullscreen" >

2.通過覆蓋Activity類的方法禁用后退按鈕:

@Override
public void onBackPressed() {
    return;
}

3.將以下字符串添加到清單(相應Activity意圖過濾器):

<intent-filter>
    <action android:name="android.intent.action.MAIN" />
    <category android:name="android.intent.category.HOME" />
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

現在,您可以使用應用程序替換默認主屏幕。 但是,通過單擊“最近的應用程序”按鈕並選擇另一個按鈕,退出應用程序的能力仍然存在。

4.為了避免所有其他離開應用程序的方法,我添加了一項服務,每次暫停活動時都會啟動該服務。 此服務重新啟動應用程序並發送有關它的通知。 服務代碼:

public class RelaunchService extends Service {
    private Notification mNotification;
    private Timer mTimer;

    public RelaunchService() {
    }

    @Override
    public void onCreate(){
        super.onCreate();
        if (mNotification == null) {
            Context context = getApplicationContext();
            Intent notificationIntent = new Intent(this, FullscreenActivity.class);
            PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
                    notificationIntent, 0);
            Notification.Builder mBuilder = new Notification.Builder(context)
                    .setSmallIcon(android.R.drawable.ic_dialog_info)
                    .setWhen(System.currentTimeMillis())
                    .setContentIntent(contentIntent)
                    .setContentTitle("Your app title")
                    .setContentText("App is being relaunched");
            mNotification = mBuilder.getNotification();

            mTimer = new Timer("LaunchTimer");
        }
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        super.onStartCommand(intent, flags, startId);
        startForeground(1, mNotification);
        mTimer.schedule(new TimerTask() {
            @Override
            public void run() {
                Intent intent = new Intent(RelaunchService.this, YourActivity.class);
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                startActivity(intent);
            }
        }, 300);
        return START_STICKY;
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        stopForeground(true);
        mTimer.cancel();
    }

    @Override
    public IBinder onBind(Intent intent) {
        // TODO: Return the communication channel to the service.
        throw new UnsupportedOperationException("Not yet implemented");
    }
}

代碼添加到Activity類:

@Override
protected void onResume() {
    super.onResume();
    exitAllowed = false;
    Intent servIntent = new Intent(this, RelaunchService.class);
    stopService(servIntent);
}

@Override
protected void onPause() {
    super.onPause();
    savePersistentData();
    if (!exitAllowed) {
        Intent servIntent = new Intent(this, RelaunchService.class);
        startService(servIntent);
    }
}

當您要關閉應用程序時,應將exitAllowed布爾變量賦值為true 您可以考慮某種方法,例如單擊“退出”按鈕。 在我的情況下,需要密碼才能退出。

在三星手機中可以使用非root解決方案,看看免費的Superlock應用程序

https://play.google.com/store/apps/details?id=com.superkiosk.ospolice.superlocklite&hl=en_GB

您無需創建自定義ROM或甚至根設備來獲取信息亭模式。 通常強烈建議不要使用現場設備,尤其是如果您的應用程序具有敏感數據。

12oz鼠標的答案( https://stackoverflow.com/a/29560438/2888763 )可能在大多數情況下有效,但它並不完全安全。 您的應用或服務總是可能被系統或崩潰殺死,從而使用戶可以完全訪問該設備。

實現自助終端模式的一種方法是使用谷歌的鎖定任務模式 - 這與屏幕固定不同( https://developer.android.com/work/cosu.html )。 其中的鏈接列出了一些鎖定任務模式功能,例如:將一個應用程序固定到主屏幕並禁用/隱藏Home和Recents按鈕。 該鏈接還說明了為什么Google解決方案的最大問題是設置它的復雜性。 您必須“使用第三方企業移動管理(EMM)解決方案”或“創建您自己的DPC應用程序”。 如果您無法訪問Google Play服務,Google的COSU解決方案也可能無效。

另一個選擇是使用像Mason( https://bymason.com/ )這樣的移動部署平台,您可以在幾分鍾內使用自助服務終端模式等功能構建自定義Android操作系統。 然后,您可以將操作系統或應用程序更新遠程部署到所有設備。

請直接告訴我: trevor @ bymason.com

免責聲明:我為梅森工作

我最終確定了這個解決方案,不需要root,外部應用程序,可以在瀏覽器,webapps和本機應用程序上使用:

沉浸式全屏模式

  1. 使用adb,檢查您的設備是否與adb devices (必須啟用開發選項)
  2. 找到您要全屏顯示的應用的ID(如果它是一個webapp,它使用的是瀏覽器,如org.mozilla.firefoxcom.android.chrome ),它位於Play商店網址: https://play.google.com/store/apps/details?id=org.mozilla.firefoxhttps://play.google.com/store/apps/details?id=org.mozilla.firefox
  3. adb shell settings put global policy_control immersive.full=org.mozilla.firefox命令adb shell settings put global policy_control immersive.full=org.mozilla.firefox用你的id替換org.mozilla.firefox

更多信息: https//www.howtogeek.com/302194/how-to-force-any-android-app-into-fullscreen-immersive-mode-without-rooting/

與屏幕釘扎相結合:

  1. 在Android設備上啟動“設置”應用。
  2. 向下滾動,直到找到“安全”選項。 點擊它。
  3. 在“安全性”頁面的底部,點擊屏幕固定。
  4. 將開關滑動到“開”位置。
  5. 打開您的應用,使用最近的應用進入視圖,然后點按當前應用預覽中的圖釘圖標(右下角)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM