Check if your Android device supports certain features

Source: Internet
Author: User

When we develop the app, the application may require the device to support certain features to ensure that the application runs. For example need support phone, NFC. Gyroscope and so on.

We can use the Hassystemfeature method of the Packagemanager object to check whether certain features are supported by the current device.

The first method:

Use code to check if the device supports certain features. This method is better. Because no matter where the app comes from. Can accurately determine whether the device supports the functionality required by the application.

Code:

Packagemanager pm =Getpackagemanager (); //gets whether the phone is supported                Booleantelephony =pm. Hassystemfeature (Packagemanager.feature_telephony); //whether GSM is supported                BooleanGSM =pm. Hassystemfeature (PACKAGEMANAGER.FEATURE_TELEPHONY_GSM); //whether CDMA is supported                BooleanCDMA =pm. Hassystemfeature (PACKAGEMANAGER.FEATURE_TELEPHONY_CDMA); /** Use the Hassystemfeature method to check if the device is otherwise functional. such as gyroscopes, NFC, Bluetooth, etc.,*/                BooleanNFC =pm.hassystemfeature (PACKAGEMANAGER.FEATURE_NFC); Toast.maketext (mainactivity. This, String.Format ("NFC Support%s", NFC), Toast.length_short). Show ();

PS: We use hassystemfeature to check for more content. such as WIFI,NFC, Bluetooth and so on.


The second method:

Use the <uses-feature/> tag in the Androidmanifest.xml file to tell Android Market that this application must meet the specified features in the tag before it can be used, so that Android The market will filter all unsupported devices according to the application's specified requirements. The downside of this approach is that you can only filter apps in Android Market. If you're using an app from another source, it's no effect.


For example, check if your phone supports NFC:
<uses-feature android:name= "ANDROID.HARDWARE.NFC" android:required= "true"/>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.