Android 3.0 Use Physical Keyboard Setting

限于喜欢 提交于 2020-01-15 08:08:24

问题


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: http://i.stack.imgur.com/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.


回答1:


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.



来源:https://stackoverflow.com/questions/5384842/android-3-0-use-physical-keyboard-setting

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