Android 中的 Kiosk 模式

发布于 2024-08-18 02:52:40 字数 215 浏览 5 评论 0原文

我正在评估是否以及如何将 CF .NET 企业应用程序移植到 Android 设备上运行。 Windows Mobile 手机上的应用程序以信息亭模式运行,应用程序在启动后以全屏模式自动启动,并且用户无法意外或自愿访问手机的任何其他部分。

Android 上是否可以在启动后仅自动启动一个应用程序,并防止用户意外(或故意)访问 Android 设备的任何其他部分?

I'm in the process of evaluating if and how a CF .NET enterprise application can be ported to run on Android devices. The application on Windows Mobile phones are run in kiosk mode where the application autostart in fullscreen-mode after booting and with the users unable to accidentally or willingly access any other parts of the phone.

Is it possible on Android to have only one application autostart after booting and prevent users from accidentally (or willingly) access any other parts of the Android device?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(11

感情旳空白 2024-08-25 02:52:40

您可以通过监听 BroadcastReceiver 中的 android.intent.action.BOOT_COMPLETED Intent 在启动时自动启动应用程序,并从那里启动您的 Activity。在活动中,您可以将自己注册为新的默认主屏幕[1]并处理按键。

我认为在某些情况下,如果不修改框架就无法处理(例如长按主页以显示当前活动的应用程序) - 但我也可能是错误的。

但对于原型来说这可能就足够了。

玩得开心修补!

[1]:

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

You can autostart applications on boot by listening to the android.intent.action.BOOT_COMPLETED intent in a BroadcastReceiver and start your Activity from there. In the Activity you can register yourself as the new default homescreen[1] and handle the keys.

I think there are some instances that you can't handle without modifying the framework (like longpress on Home to show currently active Applications) - I could also be mistaken though.

But for a prototype that could be sufficient.

Have fun tinkering!

[1]:

<intent-filter>
 <action android:name="android.intent.action.MAIN" />
 <category android:name="android.intent.category.HOME" />
 <category android:name="android.intent.category.DEFAULT" />
</intent-filter>
吃→可爱长大的 2024-08-25 02:52:40

您可以对此进行自定义(禁用对菜单的访问、限制应用程序添加等)以启用信息亭。 http://code.google.com/p/android-launcher-plus/

You could customise this (disable access to menu, limit application addition etc) to enable kiosk. http://code.google.com/p/android-launcher-plus/

-柠檬树下少年和吉他 2024-08-25 02:52:40

在新的 Android L 预览版中,Google 宣布了任务锁定,这正是如此。不过它似乎确实需要root。

L 开发者预览版引入了新的任务锁定 API,可以让
您暂时限制用户离开您的应用程序或
被通知打断。例如,如果您
正在开发一款教育应用程序来支持高风险评估
对 Android 的要求。一旦您的应用程序激活此模式,用户将
无法查看通知、访问其他应用程序或返回到
主屏幕,直到您的应用退出该模式。

为了防止未经授权的使用,只有授权的应用程序才能激活任务
锁定。此外,任务锁定授权必须由
专门配置的设备所有者应用程序,通过
android.app.admin.DevicePolicyManager.setLockTaskComponents() 方法。

要设置设备所有者,请按以下步骤操作:

  • 将运行 Android userdebug 版本的设备附加到您的开发中
    机器。
  • 安装您的设备所有者应用。
  • 创建 device_owner.xml 文件
    并将其保存到设备上的/data/system目录中。
$ adb root
$ adb shell stop
$ rm /tmp/device_owner.xml
$ echo "<?xml version='1.0' encoding='utf-8' standalone='yes' ?>" >> /tmp/device_owner.xml
$ echo "&device-owner package=\"<your_device_owner_package>\" name=\"*<your_organization_name>\" />" >> /tmp/device_owner.xml
$ adb push /tmp/device_owner.xml /data/system/device_owner.xml
$ adb reboot

在您的应用中使用任务锁定 API 之前,请验证您的
活动通过调用授权
DevicePolicyManager.isLockTaskPermission()。

要激活任务锁定,请调用android.app.Activity.startLockTask()
来自您授权的活动。

当任务锁定处于活动状态时,以下行为将生效:

  • 状态栏为空白,显示用户通知和状态信息
    被隐藏。
  • “主页”和“最近使用的应用程序”按钮已隐藏。
  • 其他应用程序可能会
    不开展新的活动。
  • 当前应用可能会启动新的活动,
    只要这样做不会创建新任务。
  • 用户仍处于锁定状态
    在您的应用程序上,直到授权活动调用
    Activity.stopLockTask()

In the new Android L Preview, Google has announced Task Locking, which does exactly that. It does seem to need root however.

The L Developer Preview introduces a new task locking API that lets
you temporarily restrict users from leaving your app or being
interrupted by notifications. This could be used, for example, if you
are developing an education app to support high stakes assessment
requirements on Android. Once your app activates this mode, users will
not be able to see notifications, access other apps, or return to the
Home screen, until your app exits the mode.

To prevent unauthorized usage, only authorized apps can activate task
locking. Furthermore, task locking authorization must be granted by a
specially-configured device owner app, through the
android.app.admin.DevicePolicyManager.setLockTaskComponents() method.

To set up a device owner, follow these steps:

  • Attach a device running an Android userdebug build to your development
    machine.
  • Install your device owner app.
  • Create a device_owner.xml file
    and save it to the /data/system directory on the device.
$ adb root
$ adb shell stop
$ rm /tmp/device_owner.xml
$ echo "<?xml version='1.0' encoding='utf-8' standalone='yes' ?>" >> /tmp/device_owner.xml
$ echo "&device-owner package=\"<your_device_owner_package>\" name=\"*<your_organization_name>\" />" >> /tmp/device_owner.xml
$ adb push /tmp/device_owner.xml /data/system/device_owner.xml
$ adb reboot

Before using the task locking API in your app, verify that your
activity is authorized by calling
DevicePolicyManager.isLockTaskPermitted().

To activate task locking, call android.app.Activity.startLockTask()
from your authorized activity.

When task locking is active, the following behavior takes effect:

  • The status bar is blank, and user notifications and status information
    is hidden.
  • The Home and Recent Apps buttons are hidden.
  • Other apps may
    not launch new activities.
  • The current app may start new activities,
    as long as doing so does not create new tasks.
  • The user remains locked
    on your app until an authorized activity calls
    Activity.stopLockTask().
风筝在阴天搁浅。 2024-08-25 02:52:40

经过一段时间的搜索后,我想出了一个很好的解决方案。不过,这仅适用于已取得 root 权限的设备,但我想如果它仅适用于这个应用程序,那么取得 root 权限应该不是问题。

另请查看 http://thebitplague。 wordpress.com/2013/04/05/kiosk-mode-on-the-nexus-7/ 另一种方式

After searching for this for a while I've come up with a good solution. This only works on rooted devices though, but I guess if it's just for this one app then rooting it shouldn't be a problem.

Also check out http://thebitplague.wordpress.com/2013/04/05/kiosk-mode-on-the-nexus-7/ for another way

我三岁 2024-08-25 02:52:40

在启动时启动应用程序

实现此目的的最佳方法是将应用程序设置为启动器

<activity ...
  android:launchMode="singleInstance"
  android:windowActionBar="false">
    <intent-filter>
      <action android:name="android.intent.action.MAIN" />
      <category android:name="android.intent.category.HOME" />
      <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
</activity>

锁定应用程序

最可靠的方法是使用具有 Lollipop 或更高版本的设备,并且

startLockTask

首先必须将应用程序设置为设备所有者。请注意,您的设备必须未配置:如果您已注册,则应恢复出厂设置并跳过帐户注册。

为了能够注册您的应用程序,您必须首先设置一个 DeviceAdminReceiver 组件:

package com.example.myapp;

public class MyDeviceAdminReceiver extends android.app.admin.DeviceAdminReceiver {
    @Override
    public void onEnabled(Context context, Intent intent) {
        Toast.makeText(context, "Device admin permission received", Toast.LENGTH_SHORT).show();
    }

    @Override
    public CharSequence onDisableRequested(Context context, Intent intent) {
        return "are you sure?";
    }

    @Override
    public void onDisabled(Context context, Intent intent) {
        Toast.makeText(context, "Device admin permission revoked", Toast.LENGTH_SHORT).show();
    }


    @Override
    public void onLockTaskModeExiting(Context context, Intent intent) {
        // here you must re-lock your app. make your activity know of this event and make it call startLockTask again!
    }
}

一旦您拥有未配置的设备,您可以从 adb 启动以下命令(无需 root),

adb shell dpm set-device-owner com.example.myapp/.MyDeviceAdminReceiver

以避免 Android 询问用户固定权限你必须调用你的应用程序
setLockTaskPackages了!

终于

@Override
public void onResume(){
    super.onResume();
    DevicePolicyManager mDevicePolicyManager = (DevicePolicyManager) getSystemService(
            Context.DEVICE_POLICY_SERVICE);
    ComponentName mAdminComponentName = new ComponentName(getApplicationContext(), MyDeviceAdminReceiver.class);
    mDevicePolicyManager.setLockTaskPackages(mAdminComponentName, new String[]{getPackageName()});
    startLockTask();
}
@Override
public void finish(){
    stopLockTask();
    super.finish();
}

Starting your app on boot

the BEST way to accomplish this is setting your app as the launcher

<activity ...
  android:launchMode="singleInstance"
  android:windowActionBar="false">
    <intent-filter>
      <action android:name="android.intent.action.MAIN" />
      <category android:name="android.intent.category.HOME" />
      <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
</activity>

Locking your app

the most reliable way is to use a device with Lollipop or greater and make use of

startLockTask

first you must set your app as the device owner. NB your device must be unprovisioned: if you registered it you should do a factory reset and skip the account registration.

to be able to register your app you must first setup a DeviceAdminReceiver component:

package com.example.myapp;

public class MyDeviceAdminReceiver extends android.app.admin.DeviceAdminReceiver {
    @Override
    public void onEnabled(Context context, Intent intent) {
        Toast.makeText(context, "Device admin permission received", Toast.LENGTH_SHORT).show();
    }

    @Override
    public CharSequence onDisableRequested(Context context, Intent intent) {
        return "are you sure?";
    }

    @Override
    public void onDisabled(Context context, Intent intent) {
        Toast.makeText(context, "Device admin permission revoked", Toast.LENGTH_SHORT).show();
    }


    @Override
    public void onLockTaskModeExiting(Context context, Intent intent) {
        // here you must re-lock your app. make your activity know of this event and make it call startLockTask again!
    }
}

once you have an unprovisioned device you can launch the following command from adb (no root required)

adb shell dpm set-device-owner com.example.myapp/.MyDeviceAdminReceiver

to avoid android asking the user permissions to pin your app you must call
setLockTaskPackages

finally!

@Override
public void onResume(){
    super.onResume();
    DevicePolicyManager mDevicePolicyManager = (DevicePolicyManager) getSystemService(
            Context.DEVICE_POLICY_SERVICE);
    ComponentName mAdminComponentName = new ComponentName(getApplicationContext(), MyDeviceAdminReceiver.class);
    mDevicePolicyManager.setLockTaskPackages(mAdminComponentName, new String[]{getPackageName()});
    startLockTask();
}
@Override
public void finish(){
    stopLockTask();
    super.finish();
}
[旋木] 2024-08-25 02:52:40

Google 最近发布了 Android Management API,它允许轻松为运行 Android 5.1 或更高版本的任何 Android 设备设置 kiosk 模式,并设置各种其他策略。

Google recently released the Android Management API which allows to easily set up kiosk mode for any Android devices running Android 5.1 or above, and also to set various other policies.

星星的軌跡 2024-08-25 02:52:40

Android 开发人员的设置单一用途设备页面已经描述了您可以轻松访问的内容从那里知道更多的事情。

现在,可以轻松将 Android 6.0 Marshmallow 及更高版本设备配置为公司拥有的一次性 (COSU) 设备。

Set up Single-Purpose Devices Page of android developer have described this things you can easily get to know more things from there.

Now it is easy to configure Android 6.0 Marshmallow and later devices as corporate-owned, single-use (COSU) devices.

嘴硬脾气大 2024-08-25 02:52:40

在此 论坛中找到了另一种可能的技术发布。引用该帖子:

http:// /www.basic4ppc.com/forum/basic4android-getting-started-tutorials/10839-android-kiosk-mode-tutorial.html

使用以下方法,您可以构建一个应用程序,该应用程序将
防止“普通”用户玩除您的之外的任何游戏
应用程序。

该应用程序由两个模块组成。主要活动和
服务。该服务被配置为在引导时启动。当服务
启动后它会检查该活动是否正在运行。如果不是
运行它使用计时器来启动主要活动。

当活动暂停时,它会安排服务一次性启动
第二:代码:

Sub Activity_Pause (UserClosed As Boolean)
    If kiosk Then StartServiceAt(KioskService, DateTime.Now + 1 * DateTime.TicksPerSecond, false)    
End Sub

如果用户按主屏幕,将出现主屏幕
几秒钟。但是您的应用程序将返回到前面
几秒钟后,用户将无法与任何
其他应用程序或更改设置。

该服务被设置为前台服务。这会阻止 Android
以免扼杀我们的服务。按“停止”按钮停用信息亭
模式。

似乎有示例 kiosk 模式代码 ZIP 文件可供下载< /a>,也是。

Found another possible technique in this forum post. Quoting that post:

http://www.basic4ppc.com/forum/basic4android-getting-started-tutorials/10839-android-kiosk-mode-tutorial.html

Using the following methods you can build an application that will
prevent "regular" users from playing with anything other than your
application.

The application is made of two modules. The main activity and a
service. The service is configured to start at boot. When the service
is started it checks if the activity is running or not. If it is not
running it uses a timer to start the main activity.

When the activity is paused it schedules the service to start in one
second: Code:

Sub Activity_Pause (UserClosed As Boolean)
    If kiosk Then StartServiceAt(KioskService, DateTime.Now + 1 * DateTime.TicksPerSecond, false)    
End Sub

If the user presses on the home screen, the home screen will appear
for several seconds. However your application will return to the front
after a few seconds and the user will not be able to interact with any
other applications or change the settings.

The service is set to be a foreground service. This prevents Android
from killing our service. Press on the Stop button to deactivate kiosk
mode.

There appears to be an example kiosk-mode code ZIP file available for download, too.

忆离笙 2024-08-25 02:52:40

Xposed框架可以做到这一点。它需要 root,并且有可能无法在所有平台上运行。在 android.app.StatusBarManager 类中查找 disable() 方法。

在 Android 源代码中

在这里查看如何编写自己的模块:
Xpose开发教程

比你第一眼想象的要容易得多。祝你好运!

Xposed framework can do this. It needs root and there is a possibility that it won't work on every and all platforms. Look for disable() method in class android.app.StatusBarManager.

Here in Android source code

Look here on how to write your own module:
Xposed development tutorial

It's much easier than you think at first glance. Good Luck!

凉城凉梦凉人心 2024-08-25 02:52:40

除了使用 BOOT 接收器设置您的应用程序之外,还有此答案为了防止状态栏扩展,此解决方案在 4.4 及更高版本上作为完整的信息亭应用程序运行:

放置在 onCreate() 中:

    final View view = (View) findViewById(android.R.id.content);
    if (view != null) {
        //"hides" back, home and return button on screen. 
        view.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE |
                                   View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
                                   View.SYSTEM_UI_FLAG_IMMERSIVE |
                                   View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY |
                                   View.SYSTEM_UI_FLAG_FULLSCREEN);
        view.setOnSystemUiVisibilityChangeListener
                (new View.OnSystemUiVisibilityChangeListener() {
                    @Override
                    public void onSystemUiVisibilityChange(int visibility) {
                        // Note that system bars will only be "visible" if none of the
                        // LOW_PROFILE, HIDE_NAVIGATION, or FULLSCREEN flags are set.
                        if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) {
                            view.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE |
                                    View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
                                    View.SYSTEM_UI_FLAG_IMMERSIVE |
                                    View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY |
                                    View.SYSTEM_UI_FLAG_FULLSCREEN);
                        }
                    }
                });
    }

这将完全隐藏后退按钮、应用程序和主页按钮。

Along with setting up your application with a BOOT receiver, and this answer for preventing status bar expansion, this solution works on 4.4 and above as a complete kiosk app :

Place in your onCreate():

    final View view = (View) findViewById(android.R.id.content);
    if (view != null) {
        //"hides" back, home and return button on screen. 
        view.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE |
                                   View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
                                   View.SYSTEM_UI_FLAG_IMMERSIVE |
                                   View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY |
                                   View.SYSTEM_UI_FLAG_FULLSCREEN);
        view.setOnSystemUiVisibilityChangeListener
                (new View.OnSystemUiVisibilityChangeListener() {
                    @Override
                    public void onSystemUiVisibilityChange(int visibility) {
                        // Note that system bars will only be "visible" if none of the
                        // LOW_PROFILE, HIDE_NAVIGATION, or FULLSCREEN flags are set.
                        if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) {
                            view.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE |
                                    View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
                                    View.SYSTEM_UI_FLAG_IMMERSIVE |
                                    View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY |
                                    View.SYSTEM_UI_FLAG_FULLSCREEN);
                        }
                    }
                });
    }

This will completely hide the back button, apps and home button.

我们的影子 2024-08-25 02:52:40

Kiosk 模式只不过是在您打开 Android 设备时锁定单个或一组应用程序。这可以通过锁定任务模式来实现。当设备在锁定任务模式下运行时,用户通常无法看到通知、访问非白名单应用程序或返回主屏幕。

设备策略控制器 (DPC) 可以将系统处于锁定任务模式时可以运行的应用程序列入白名单。由于它是用于特定目的的专用设备,因此使用该设备的人无法离开锁定任务模式。 Android 5.0及以上版本的设备可以在锁定任务模式下运行。

    •        Whitelisting the applications

第一步是通过 DPC 将应用程序列入白名单。
将可以在锁定任务模式下使用的应用程序列入白名单。

DPC 可以通过调用DevicePolicyManager.setLockTaskPackages()

    ▪         Start lock task mode

白名单完成后,DPC 可以调用以下函数来启动锁定任务。

ActivityOptions.setLockTaskEnabled()

您可以在此处找到有关锁定任务模式的更多详细信息。 https://developer.android.com/work/dpc/专用设备/锁定任务模式

Kiosk mode is nothing but locking a single or set of applications when you switch on an android device. This can be achieved by lock task mode. When the device runs in lock task mode, users typically can’t see notifications, access non-whitelisted apps, or return to the home screen.

The Device policy controller (DPC) can whitelist the app that can run when the system is in lock task mode. Since its a dedicated device for a specific purpose the person using the device can't leave lock task mode. The device which are Android 5.0 and higher can run in lock task mode.

    •        Whitelisting the applications

First step is to whitelist the application by DPC.
DPC can whitelist the apps which can be used in lock task mode by calling

DevicePolicyManager.setLockTaskPackages()

    ▪         Start lock task mode

Once the whitelisting is done, DPC can call the below function to start the lock task.

ActivityOptions.setLockTaskEnabled()

You can find more details regarding the lock task mode here. https://developer.android.com/work/dpc/dedicated-devices/lock-task-mode

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文