有没有什么办法来检查设备是否支持手写笔输入? [英] Is there any way to check if device supports stylus input?

查看:913
本文介绍了有没有什么办法来检查设备是否支持手写笔输入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想只显示设备是否支持手写笔进行输入的菜单项。

不幸的是我找到了什么检查设备或屏幕支持手写笔/ SPEN输入。

编辑: 我可以手写笔和手指之间的区别后MotionEvent使用event.getToolType被触发()。 如果Tooltype刀具是TOOL_TYPE_STYLUS我可以肯定的是它支持手写笔。 如果不是我可以猜测,如果有一个pressure> 0(与如何检测,如果屏幕是电容或电阻中Android设备?

不过,我想知道在我活动的onCreate方法。

以下是有点不支持,对我是行不通的。

 配置配置= getResources()getConfiguration()。
如果(config.touchscreen == Configuration.TOUCHSCREEN_STYLUS)
    Toast.makeText(这一点,TOUCHSCREEN_STYLUS,Toast.LENGTH_SHORT).show();
 

解决方案

在这里,你去(从Android文档) - 似乎只在4.0及以上,虽然支持。 http://developer.android.com/about/versions/android-4.0.html

  

安卓现在提供的API用于从触笔输入接收输入   设备,诸如数字化纸簿的外围或触笔启用触摸   屏幕。

     

手写输入操作以类似的方式接触或鼠标输入。   在触笔与数字化仪接触,应用程序接收   触摸事件,就像他们将当手指被用于触摸   显示。当触笔悬停数字化仪之上,应用程序   收到悬停事件,就像他们当鼠标指针是   移动在显示屏上时,没有按钮是pressed。

     

您的应用程序可以手指,鼠标,手写笔和区分   通过查询每个指针相关的工具型橡皮擦输入   在MotionEvent使用的 getToolType()的。目前定义的刀具类型   主要有: TOOL_TYPE_UNKNOWN TOOL_TYPE_FINGER TOOL_TYPE_MOUSE    TOOL_TYPE_STYLUS TOOL_TYPE_ERASER 。通过查询工具类型,   你的应用可以选择不同的方式处理手写笔输入   从手指或鼠标输入

     

您的应用程序也可以查询该鼠标或手写笔按钮   pressed通过查询一个MotionEvent的按钮状态    getButtonState()的。目前定义的按钮状态是:    BUTTON_PRIMARY BUTTON_SECONDARY BUTTON_TERTIARY BUTTON_BACK ,然后    BUTTON_FORWARD 。为方便起见,后退和前进鼠标按钮   自动映射到 KEY code_BACK KEY code_FORWARD 键。   您的应用程序可以处理这些密​​钥支持鼠标右键的基础   后退和前进导航。

     

在除了precisely测量的位置和pressure   接触,一些手写笔输入设备还报告之间的距离   针尖和数字化仪,触针的倾斜角,并且   手写笔定位角度。应用程序可以查询这些信息   使用的 getAxisValue()的与轴codeS AXIS_DISTANCE AXIS_TILT ,然后    AXIS_ORIENTATION

I want to show an menu item only if the device supports the stylus for input.

Unfortunately i've found nothing check if the device or the display supports the stylus/Spen for input.

Edit: I can distinguish between Stylus and Finger after a MotionEvent is triggered using event.getToolType(). If the tooltype is TOOL_TYPE_STYLUS i can be sure that it supports the stylus. If not i can guess if there is a pressure > 0 (relating to how to detect if the screen is capacitive or resistive in an Android device?)

But i would like to know it in the onCreate method of my activity.

Following is somehow not supported and does not work for me.

Configuration config = getResources().getConfiguration();
if (config.touchscreen == Configuration.TOUCHSCREEN_STYLUS)
    Toast.makeText(this, "TOUCHSCREEN_STYLUS", Toast.LENGTH_SHORT).show();

解决方案

Here you go (from the Android documentation) - seems to only be supported in 4.0 and up though. http://developer.android.com/about/versions/android-4.0.html

Android now provides APIs for receiving input from a stylus input device such as a digitizer tablet peripheral or a stylus-enabled touch screen.

Stylus input operates in a similar manner to touch or mouse input. When the stylus is in contact with the digitizer, applications receive touch events just like they would when a finger is used to touch the display. When the stylus is hovering above the digitizer, applications receive hover events just like they would when a mouse pointer was being moved across the display when no buttons are pressed.

Your application can distinguish between finger, mouse, stylus and eraser input by querying the "tool type" associated with each pointer in a MotionEvent using getToolType(). The currently defined tool types are: TOOL_TYPE_UNKNOWN, TOOL_TYPE_FINGER, TOOL_TYPE_MOUSE, TOOL_TYPE_STYLUS, and TOOL_TYPE_ERASER. By querying the tool type, your application can choose to handle stylus input in different ways from finger or mouse input.

Your application can also query which mouse or stylus buttons are pressed by querying the "button state" of a MotionEvent using getButtonState(). The currently defined button states are: BUTTON_PRIMARY, BUTTON_SECONDARY, BUTTON_TERTIARY, BUTTON_BACK, and BUTTON_FORWARD. For convenience, the back and forward mouse buttons are automatically mapped to the KEYCODE_BACK and KEYCODE_FORWARD keys. Your application can handle these keys to support mouse button based back and forward navigation.

In addition to precisely measuring the position and pressure of a contact, some stylus input devices also report the distance between the stylus tip and the digitizer, the stylus tilt angle, and the stylus orientation angle. Your application can query this information using getAxisValue() with the axis codes AXIS_DISTANCE, AXIS_TILT, and AXIS_ORIENTATION.

这篇关于有没有什么办法来检查设备是否支持手写笔输入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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