I am developing an android application and I need android device features. I know that, by using package manager, getSystemAvailableFeatures
method should be available. Still the method is not available Can any one help me by post some example or source code related to that.
I use the following function to determine if a feature is available:
public final static boolean isFeatureAvailable(Context context, String feature) {
final PackageManager packageManager = context.getPackageManager();
final FeatureInfo[] featuresList = packageManager.getSystemAvailableFeatures();
for (FeatureInfo f : featuresList) {
if (f.name != null && f.name.equals(feature)) {
return true;
}
}
return false;
}
The usage (i.e from Activity class):
if (isFeatureAvailable(this, PackageManager.FEATURE_CAMERA)) {
...
}
If you know the feature you want to check then you don't need to enumerate all system features and check against the one you're looking for. Since API level 5 you can use the PackageManager.hasSystemFeature() function to do the same job as the isFeatureAvailable() function shown in the previous answer.
For example...
PackageManager packageManager = this.getPackageManager();
if (packageManager.hasSystemFeature(PackageManager.FEATURE_NFC))
Log.d("TEST", "NFC IS AVAILABLE\n");
else
Log.d("TEST", "NFC IS *NOT* AVAILABLE\n");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With