Android 3.0 使用物理键盘设置
背景:
我最近购买了一台摩托罗拉 XOOM 平板电脑以及桌面扩展坞和蓝牙键盘配件。
扩展坞和键盘工作得很好,但是当我将平板电脑从扩展坞上取下并远离办公桌时,键盘仍然与设备配对,我必须手动更改设置才能使用软键盘。当我将其放回坞站时也是如此,我需要手动将其切换回来。这不是一个大问题,但最好不用考虑它。
因此,我尝试从市场上下载一个应用程序,该应用程序可以在连接或断开电源时简单地打开和关闭蓝牙,该应用程序在一段时间内运行良好,但后台服务会在一段时间后终止并变得毫无用处,直到我手动重新启动它。
重点:我正在尝试为我的平板电脑编写一个小应用程序/服务,它可以识别平板电脑何时已对接/脱离对接,并相应地切换“使用物理键盘”设置。
我已经开始使用 BroadcastReciever 来识别 Dock 状态:
public class DockBroadcastReciever extends BroadcastReceiver { private final String DOCK_STATE_LABEL = "android.intent.extra.DOCK_STATE"; @Override public void onReceive(Context context, Intent intent) { Bundle extras = intent.getExtras(); String message = (extras.getInt(DOCK_STATE_LABEL) == Intent.EXTRA_DOCK_STATE_UNDOCKED) ? "Undocked" : "Docked"; Toast toast = Toast.makeText(context, message, Toast.LENGTH_LONG); toast.show(); } }
但是我无法找出事件触发后更新设置的最佳方法。我已经使用InputMethodManager研究了一些示例,但所有方法似乎都需要特定的EditText或其他一些输入来绑定。
此外,我似乎无法在文档中的任何位置找到表示该设置的相应常量,但从图形上看,它位于此处: https://i.sstatic.net/esFaw.png
有人能帮我解决这个问题吗?
我希望有一个改变设置的解决方案,但我也愿意接受其他想法。
Background:
I recently purchased a Motorola XOOM Tablet along with the Desktop Dock and Bluetooth Keyboard accessories.
The dock and keyboard work great, but when I take the tablet off the dock to move away from my desk, the keyboard still remains paired with the device and I have to manually change the settings to use the soft keyboard. The same goes for when I set it back on the dock, I need to manually switch it back. It's not a huge problem, but it would be nice not to have to think about it.
So I tried downloading an app from the market that simply toggled Bluetooth on and off when connected or disconnected from a power source, which worked well for a while, but the background service would die after period and become useless until I manually restarted that.
TO THE POINT: I'm trying to write a little app/service for my tablet that will recognize when it has been docked/undocked and switch the "Use Physical Keyboard" setting accordingly.
I have started with a BroadcastReciever to recognize the Dock State:
public class DockBroadcastReciever extends BroadcastReceiver { private final String DOCK_STATE_LABEL = "android.intent.extra.DOCK_STATE"; @Override public void onReceive(Context context, Intent intent) { Bundle extras = intent.getExtras(); String message = (extras.getInt(DOCK_STATE_LABEL) == Intent.EXTRA_DOCK_STATE_UNDOCKED) ? "Undocked" : "Docked"; Toast toast = Toast.makeText(context, message, Toast.LENGTH_LONG); toast.show(); } }
But I'm having trouble figuring out the best way to update the setting after the event is fired. I've poked around some examples using InputMethodManager, but all the methods seem to need a specific EditText or some other input to bind to.
Furthermore, I can't seem to find a corresponding constant that represents that setting anywhere in the docs, but graphically, it is located here: https://i.sstatic.net/esFaw.png
Can anyone help me out with this?
I would like for there to be a solution for changing the setting, but I am open to other ideas as well.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我有一个应用程序可以做类似的事情。它可以根据电量切换 wifi 和蓝牙。
您需要在 AndroidManifest.xml 文件中注册其中一些内容。
http://code.google.com/p/futonic-wifioncall /source/browse/AndroidManifest.xml
项目开源站点:http://code .google.com/p/futonic-wifioncall/
这不是解决方案,但希望能为您想要实现的目标提供指导。
I have an app that does something similar. It can toggle wifi and bluetooth based on power.
You'll need to register some of this stuff in the AndroidManifest.xml file.
http://code.google.com/p/futonic-wifioncall/source/browse/AndroidManifest.xml
Project Open Source Site: http://code.google.com/p/futonic-wifioncall/
This isn't the solution but hopefully will give guidance on what you're trying to accomplish.