Kiosk Mode / Screen Pinning in Android wear

雨燕双飞 提交于 2019-12-11 01:13:00

问题


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


回答1:


Make sure you run Android L MR1 (Android 5.1). In Sony devices running L MR0 (Android 5.0), the Google implementation of startLockTask had a bug which made it possible to exit the app.

Since this is vanilla Google code, it's very likely it's the same situation on other OEM devices.

Also make sure your app's lockTaskMode is not 1, or 3 if you are not using a device admin application.

Hope this helps.

/Marek (Sony Mobile employee)




回答2:


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



来源:https://stackoverflow.com/questions/34450115/kiosk-mode-screen-pinning-in-android-wear

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