I write the NFC related declaration in the AndroidManifest like below:
<uses-feature android:name="android.hardware.nfc.hce" android:required="false"/>
<uses-permission android:name="android.permission.NFC" />
I hope in this way, google play will not filter my app in the phone without NFC function. But unfortunately, I checked the installed app, found the NFC is still required....just don't know why
PackageManager pm = getPackageManager();
try {
PackageInfo packageInfo1 = pm.getPackageInfo("My pakcage name", PackageManager.GET_CONFIGURATIONS);
if(packageInfo1 != null && packageInfo1.reqFeatures != null) {
for(FeatureInfo featureInfo : packageInfo1.reqFeatures) {
Log.d("TAG", "name:"+featureInfo.name + ", flag:" + featureInfo.flags+",version:"+featureInfo.version);
}
}
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
The output:
03-15 12:21:56.673 17052-17052/mapbox1.myapplication D/TAG: name:android.hardware.nfc.hce, flag:1,version:0
The flag in the FeatureInfo is 1, which means required....
I paste my Manifest below, removing activities and services, etc:
And the full output:
03-15 12:41:02.982 17052-17052/mapbox1.myapplication D/TAG: name:android.hardware.bluetooth_le, flag:1,version:0
03-15 12:41:02.982 17052-17052/mapbox1.myapplication D/TAG: name:android.hardware.nfc.hce, flag:1,version:0
03-15 12:41:02.982 17052-17052/mapbox1.myapplication D/TAG: name:android.hardware.camera, flag:1,version:0
03-15 12:41:02.982 17052-17052/mapbox1.myapplication D/TAG: name:android.hardware.camera.autofocus, flag:0,version:0
The required=false
in autofocus worked as desired, but NFC's required attribute not working. (android.hardware.camera
's required not working, probably because of the android.permission.CAMERA
)