English 中文(简体)
• 如何发现硬件的关键板存在?
原标题:How to detect hardware keyboard presence?

是否有办法检测目前运行的装置Im是否安装了硬件钥匙板?

我问,装置能力如何?

最佳回答

[android-developers] Re: Detect Physical Keyboard Layout (ex: QWERTY vs QWERTZ)

The flags provided by getResources().getConfiguration().keyboard are a good way of checking which keyboard (if any) is available.

问题回答

Use the following method to ascertain presence of hard keyboard at any time:
(To my knowledge, soft keyboards all lack the features tested below )

public static boolean isHardKB(Context ctx) {
    Configuration cf = ctx.getResources().getConfiguration();
    return cf.navigation==Configuration.NAVIGATION_DPAD
        || cf.navigation==Configuration.NAVIGATION_TRACKBALL
        || cf.navigation==Configuration.NAVIGATION_WHEEL;
}

通过AndroidManifest,对每个受影响活动进行实时的关键改变:

android:configChanges="keyboard|keyboardHidden|navigation"

但是,可以肯定地支持上述明显变化,(至少是)一种 du:onConfigurationChanged()。

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
    // Optionally employ  isHardKB()    
}

检测共同的下水道关键板的连接使用:

private boolean isKeyboardConnected() {
    return getResources().getConfiguration().keyboard == KEYBOARD_QWERTY;
}




相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签