Android Wear中的信息亭模式/屏幕固定 [英] Kiosk Mode / Screen Pinning in Android wear

查看:175
本文介绍了Android Wear中的信息亭模式/屏幕固定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为具有Android Lollipop的Sony Smartwatch 3开发一个Android Wear应用,似乎找不到实现工作亭模式的方法.
我到处都看过,但似乎什么也没用.
还尝试了屏幕固定,但没有办法(手动)在手表上进行,并且在我的onCreate中添加startLockStart()似乎无济于事-我仍然可以退出该应用程序.

将不胜感激的提供任何帮助或确认

解决方案

我在Medium上写了博客,以在Android Wear上实现Kiosk模式.它在Wear OS 2.X上完全可以运行,在Wear OS 1.X上可以达到90%.请检查中级.

步骤:

1:REORDER_TASKS:在应用暂停后重新排序您的应用,使其排名靠前.

ActivityManager activityManager = (ActivityManager) getApplicationContext()
                .getSystemService(Context.ACTIVITY_SERVICE);

        activityManager.moveTaskToFront(getTaskId(), 0);

2:将清单中的活动设置为类别:

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

3:替代按钮的功能

public boolean onKeyDown(int keyCode, KeyEvent event){
    if (event.getRepeatCount() == 0) {
        if (keyCode == KeyEvent.KEYCODE_STEM_1) {
            // Do stuff
            return true;
        } else if (keyCode == KeyEvent.KEYCODE_STEM_2) {
            // Do stuff
            return true;
        } else if (keyCode == KeyEvent.KEYCODE_STEM_3) {
            // Do stuff
            return true;
        }
    }
    return super.onKeyDown(keyCode, event);
}

4:通过应用主题禁用滑动功能

<style name="AppTheme" parent="@android:style/Theme.DeviceDefault">
    <item name="android:windowSwipeToDismiss">false</item>
</style>

5:在启动时重新启动应用程序

注意:

此功能不是用户友好的,除非您有充分的理由,否则Android Play商店不会批准这些功能

I am developing an Android wear app for Sony Smartwatch 3 with Android Lollipop and can't seem to find a way implement a working kiosk mode.
I've looked everywhere but nothing seems to work.
Also tried screen pinning but there isn't an option to do it on the watch (manually) and adding startLockStart() to my onCreate doesn't seem do to anything - I can still exit the app.

Any help or confirmation that it is not possible will be greatly appreciated

解决方案

I have written the blog on Medium to achieve Kiosk mode on Android wear. It works fully on Wear OS 2.X and 90% on Wear OS 1.X. Please check on Medium.

Steps :

1: REORDER_TASKS : reorder your app to top in onPause of the app.

ActivityManager activityManager = (ActivityManager) getApplicationContext()
                .getSystemService(Context.ACTIVITY_SERVICE);

        activityManager.moveTaskToFront(getTaskId(), 0);

2: set categories to activity in manifest :

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

3: Override button’s functionality

public boolean onKeyDown(int keyCode, KeyEvent event){
    if (event.getRepeatCount() == 0) {
        if (keyCode == KeyEvent.KEYCODE_STEM_1) {
            // Do stuff
            return true;
        } else if (keyCode == KeyEvent.KEYCODE_STEM_2) {
            // Do stuff
            return true;
        } else if (keyCode == KeyEvent.KEYCODE_STEM_3) {
            // Do stuff
            return true;
        }
    }
    return super.onKeyDown(keyCode, event);
}

4: Disable swipe functionality by applying theme

<style name="AppTheme" parent="@android:style/Theme.DeviceDefault">
    <item name="android:windowSwipeToDismiss">false</item>
</style>

5: Relaunch App on Boot

Note :

This functionality is not user friendly and Android Play Store wouldn’t approve of these unless you have a very strong reason

这篇关于Android Wear中的信息亭模式/屏幕固定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆