【问题标题】:Kiosk mode for android适用于 Android 的 Kiosk 模式
【发布时间】:2014-08-28 22:39:05
【问题描述】:

我有一个在 phonegap 上为 android 平板电脑编写的混合应用程序。现在我希望平板电脑只显示我的应用程序。基本上我希望平板电脑始终处于仅运行我的应用程序的信息亭模式。这样所有的按钮都被禁用了。我已经在网上寻找解决方案,其中之一是使用“surelock”,但它并没有做到以上所有。另一种选择是编写我自己的 ROM,但是我找不到任何好的教程。任何人都可以帮助我吗?

【问题讨论】:

    标签: android cordova kiosk-mode


    【解决方案1】:

    我做了很多研究,现在终于对我得到的结果感到满意。

    你基本上有两种选择:

    1. 创建您自己的自定义 ROM,这对我来说不是最佳解决方案。

    2. 使用各种技巧自定义平板电脑。

    所以我将解释第二个选项。

    首先,您需要 root 设备。有多种方法,但我更喜欢通过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();
        }
    }
    

    好的,我们已经做到了,剩下的就是让您的应用程序在启动时启动。 为此,您可以找到许多教程,只需 google。

    【讨论】:

    • 主页按钮怎么样
    • 你的意思是你有一个物理主页按钮?
    • 我愿意。这是三星的趋势。还有顶部菜单栏?
    【解决方案2】:

    在 Android L 版 (Lollipop) 中,有一个称为固定的功能,它几乎等同于 Kiosk 模式。这是一个解释如何设置的链接。

    我相信苹果首先在 iOS 中引入了这个功能。即使 OP 没有询问,我也提供了 iOS 的详细信息:

    安卓: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

    【讨论】:

      【解决方案3】:

      我认为有另一种解决方案,无需 root 设备。我的老板要求我避免生根,所以经过一些研究,我找到了这个解决方法。 结果,没有进行任何黑客攻击,系统密钥仍然存在,但用户无法离开应用程序并启动另一个应用程序。所以,我做了以下步骤。

      1。 通过编辑清单,为适当的Activity 设置不带TitleBarActionBar 的全屏主题,如下所示:

      <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。您可以考虑一些方法来做到这一点,例如通过单击“退出”按钮。在我的情况下,退出需要密码。

      【讨论】:

        【解决方案4】:

        在三星手机中可以使用非 root 解决方案,看看免费的 Superlock 应用程序

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

        【讨论】:

        • 我需要中国平板电脑的解决方案
        【解决方案5】:

        您无需创建自定义 ROM,甚至无需 root 设备即可获得信息亭模式。通常强烈建议不要在现场使用 root 设备,尤其是在您的应用包含敏感数据的情况下。

        12oz Mouse 的答案 (https://stackoverflow.com/a/29560438/2888763) 在大多数情况下可能有效,但并不完全安全。您的应用或服务总是会被系统或崩溃终止,从而使用户可以完全访问设备。

        实现自助服务终端模式的一种方法是使用谷歌的锁定任务模式 - 这与屏幕固定不同 (https://developer.android.com/work/cosu.html)。那里的链接列出了一些锁定任务模式功能,例如:将一个应用程序固定到主屏幕以及禁用/隐藏主页和最近按钮。该链接还说明了为什么 Google 解决方案的最大问题是设置的复杂性。您必须“使用第三方企业移动管理 (EMM) 解决方案”或“创建自己的 DPC 应用程序”。如果您无法访问 Google Play 服务,Google 的 COSU 解决方案也可能无法运行。

        另一种选择是使用像 Mason (https://bymason.com/) 这样的移动部署平台,您可以在几分钟内构建一个具有信息亭模式等功能的自定义 Android 操作系统。然后,您可以将操作系统或应用更新远程部署到您的所有设备。

        欢迎直接联系我:trevor @ bymason.com

        免责声明:我为 Mason 工作

        【讨论】:

          【解决方案6】:

          我最终选择了这个解决方案,不需要根、外部应用程序,并且可以在浏览器、网络应用程序和本机应用程序上使用:

          沉浸式全屏模式

          1. 使用 adb,通过adb devices 检查您的设备是否可见(必须启用开发选项)
          2. 找到您想要全屏显示的应用程序的 ID(如果是 Web 应用程序,它是它使用的浏览器,例如 org.mozilla.firefoxcom.android.chrome)它在 Play 商店的 url:https://play.google.com/store/apps/details?id=org.mozilla.firefox
          3. 执行命令 adb shell settings put global policy_control immersive.full=org.mozilla.firefoxorg.mozilla.firefox 替换为您的 id

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

          结合屏幕固定:

          1. 在您的 Android 设备上启动“设置”应用。
          2. 向下滚动直到找到安全选项。点按它。
          3. 在安全页面底部点击屏幕固定。
          4. 将开关滑到开启位置。
          5. 打开您的应用,查看您最近使用的应用,然后点击当前应用预览上的图钉图标(右下角)

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 2016-07-13
            • 2019-01-29
            • 2011-01-05
            • 2015-09-26
            • 2018-01-24
            • 2020-12-27
            • 2019-03-31
            相关资源
            最近更新 更多