问题
I understand from the official android web site https://developer.android.com/about/versions/kitkat.html which says that "Android 4.4 introduces new platform support for secure NFC-based transactions through Host Card Emulation (HCE), for payments,..." that we can not use HCE in the devices lower than Android Kit-Kat 4.4.x.
But I want to ask if we can download an Android application which uses/contains HCE and its related classes on the device which has a version that lower than Android Kit-Kat 4.4.x?
My project manifest file has android:minSdkVersion="14"
and android:targetSdkVersion="21"
but the HCE SDK used by my project's manifest has android:minSdkVersion="19"
and android:targetSdkVersion="21"
. So does my project actually have android:minSdkVersion
set to 14 or 19?
回答1:
Can I download an application that makes use of HCE functionality to a pre-KitKat device?
Yes, if your application specifies a android:minSdkVersion
lower than 19 (Android 4.4) and if your application does not require the HCE feature (i.e. if you don't specify
<uses-feature android:name="android.hardware.nfc.hce" android:required="true" />
in the application manifest).
What if any of the libraries that I use sets a higher android:minSdkVersion
?
In that case, builing your application should fail. The manifest merger tools is supposed to discover the mismatch between your application's android:minSdkVersion
and your library dependencies' android:minSdkVersion
attributes. However, you could override this by explicitly overriding the SDK requirements of specific libraries with something like this:
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="19"
tools:overrideLibrary="package.name.of.the.library" />
When using this, your application will be able to target a lower API version. However, if the library makes use of API calls that are not part of a device's API version, these calls will lead to errors/exceptions.
What if any of the libraries that I use sets the android:required
attribute for the HCE feature?
In that case, all android:required
attributes are combined with logical OR. Hence, if one manifest indicates that the HCE feature is required, your wholöe application will require that attribute. Consequently, the application won't be available for pre-KitKat devices (e.g. Play Store will only list it for devices that have the HCE feature, which effectively limits availability to devices with Android 4.4+).
Does it even make sense to have an application that uses HCE available for pre-KitKat devices?
That depends on the functionality of your app. HCE won't work on pre-KitKat devices. Hence, if HCE is the core component of your app and the app won't be useful without it, then it does not make sense to have the app available for pre-KitKat devices.
However, if the app can switch to other communication mechanisms for pre-KitKat devices (e.g. inverse reader mode, peer-to-peer mode, QR codes/barcodes), then it could make sense to have a android:minSdkVersion
lower than 19 (and to mark the HCE feature as optional with android:required="false"
) in order to make your app available for pre-KitKat devices.
回答2:
I think Host Card Emulation (HCE) required driver/lower level framework changes. So if the device supported HCE below KitKat (4.4) it probably is something special the device manufacturer put in, similar to how only with Marshmallow (6.0) has Fingerprint Reader API but Samsung had a API for using it in their SDK for their devices.
TL;DR: Without a common API provided by the Android framework any such app would need to implement each vendor's SDK for NFC HCE and then only work for those devices which support each vendor's SDK.
来源:https://stackoverflow.com/questions/32881538/can-we-download-a-payment-application-that-uses-hce-in-phones-with-lower-than-an