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"/>