I need to check if card emulation is enable on a device. I found one method here:
boolean isDefault = CardEmulation
.getInstance(NfcAdapter.getDefaultAdapter(this))
.isDefaultServiceForCategory(
new ComponentName(this, MyPaymentService.class),
CardEmulation.CATEGORY_PAYMENT);
It looks like this works on some devices, but not for all devices.
For example, on the Samsung GT-I9300I (with Android 4.4), there is an NFC module, but it doesn't show the Tap-and-pay options in the settings.
When my app runs on that device I get the following error:
E/CardEmulation: This device does not support card emulation
09-26 16:41:13.592 2625-2625/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.android.settings, PID: 2625
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android.settings/com.android.settings.nfc.PaymentDefaultDialog}: java.lang.UnsupportedOperationException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2441)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2500)
at android.app.ActivityThread.access$900(ActivityThread.java:171)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1309)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5679)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1291)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.UnsupportedOperationException
at android.nfc.cardemulation.CardEmulation.getInstance(CardEmulation.java:159)
at com.android.settings.nfc.PaymentBackend.(PaymentBackend.java:53)
at com.android.settings.nfc.PaymentDefaultDialog.onCreate(PaymentDefaultDialog.java:57)
at android.app.Activity.performCreate(Activity.java:5582)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2405)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2500)
at android.app.ActivityThread.access$900(ActivityThread.java:171)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1309)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5679)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1291)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107)
at dalvik.system.NativeStart.main(Native Method)
However, according to the documentation, CardEmulation is available since API level 19 (Android 4.4).
So can anyone explain why I'm getting this exception? How can I overcome this problem?
The error is quite clear in the log output:
E/CardEmulation: This device does not support card emulation
This class can only be used on devices that support card emulation and AID-based routing configuration. This is also documented in the documentation of the class CardEmulation:
Use of this class requires the FEATURE_NFC_HOST_CARD_EMULATION to be present on the device.
Consequently, you must only use the method getInstance() on devices that actually support the HCE feature. Note that host card emulation is a bit misleading here since that feature is also required to manage routing configuration using an OffHostApduService declaration and to use the CardEmulation class for any operations related to OffHostApduService. So this feature applies to both, HCE and management of routing configuration for secure element based card emulation. However, some device manufacturers developed other mechanisms for testing for the availability (and potentailly also for managing the routing) of secure element based card emulation.
You can use the following code to check for the HCE feature before calling the CardEmulation.getInstance() method:
boolean isDefault = false;
if (getPackageManager().hasSystemFeature(PackageManager.FEATURE_NFC_HOST_CARD_EMULATION)) {
isDefault = CardEmulation.getInstance(NfcAdapter.getDefaultAdapter(this))
.isDefaultServiceForCategory(
new ComponentName(this, MyPaymentService.class),
CardEmulation.CATEGORY_PAYMENT);
}
Related
I use androidx.camera.camera2 library in my application. This library for SDK 21 and greater. But i want allow users start application for SDK 19 without camera2 support. I check SDK version in my code, but application crash on start. Can i exclude camera2 from dependencies for old SDK?
05-30 12:13:42.318 2000-2000/com.myapp.android E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.myapp.android, PID: 2000
java.lang.NoClassDefFoundError: android.util.Size
at androidx.camera.camera2.impl.Camera2DeviceSurfaceManager.<clinit>(Camera2DeviceSurfaceManager.java:53)
at androidx.camera.camera2.Camera2AppConfig.create(Camera2AppConfig.java:58)
at androidx.camera.camera2.impl.Camera2Initializer.onCreate(Camera2Initializer.java:44)
at android.content.ContentProvider.attachInfo(ContentProvider.java:1591)
at android.content.ContentProvider.attachInfo(ContentProvider.java:1562)
at android.app.ActivityThread.installProvider(ActivityThread.java:4790)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:4385)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4325)
at android.app.ActivityThread.access$1500(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
I recently stumbled into the same issue.
Diving deep into the CameraX code I found that CameraX is initialized in app startup through a content provider. Here is the content provider code where CameraX is being initialized.
public final class Camera2Initializer extends ContentProvider {
private static final String TAG = "Camera2Initializer";
#Override
public boolean onCreate() {
Log.d(TAG, "CameraX initializing with Camera2 ...");
CameraX.init(getContext(), Camera2AppConfig.create(getContext()));
return false;
}
}
Im not very familiar with content providers but my first taught was, this is add at the manifest level? And indeed I was right.
Looking at there manifest I found this
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="androidx.camera.camera2">
<application>
<provider
android:name=".Camera2Initializer"
android:authorities="${applicationId}.camerax-init"
android:exported="false"
android:initOrder="100"
android:multiprocess="true" />
</application>
</manifest>
There manifest gets merged into ours which will include this content provider which in the other hand initializes CameraX, we want to avoid this. So one possible way of doing so is creating our own empty content provider and adding it to our manifest with the same name. This will override there content provider.
You can look into
https://developer.android.com/studio/build/manifest-merge
for more detail about manifest merging.
So now with there content provider overriden hopefully you can call
CameraX.init(getContext(), Camera2AppConfig.create(getContext()));
only when the feature gets called and not on app startup.
Im hoping this gets fixed in later versions and allows us to initialize cameraX when we want to.
I have integrated facebook account kit in my app and it works perfectly fine on devices with higher android versions ( nougat, marshmallw, lollipop etc). On low android api's ( I have tested on huawei h3u10 android 4.2.2 ) it shows the following error when I try to change the country code:
04-25 20:31:04.664 3670-3670/com.chaatgadrive.arif.chaatgadrive
E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.NullPointerException
at android.view.ViewGroup$LayoutParams.(ViewGroup.java:5729)
at com.facebook.accountkit.ui.PhoneCountryCodeAdapter.getDropDownView(PhoneCountryCodeAdapter.java:273)
at android.support.v7.widget.AppCompatSpinner$DropDownAdapter.getDropDownView(AppCompatSpinner.java:650)
at android.support.v7.widget.AppCompatSpinner$DropDownAdapter.getView(AppCompatSpinner.java:644)
at android.support.v7.widget.DropDownListView.measureHeightOfChildrenCompat(DropDownListView.java:320)
at android.support.v7.widget.ListPopupWindow.buildDropDown(ListPopupWindow.java:1300)
at android.support.v7.widget.ListPopupWindow.show(ListPopupWindow.java:646)
at android.support.v7.widget.AppCompatSpinner$DropdownPopup.show(AppCompatSpinner.java:800)
at android.support.v7.widget.AppCompatSpinner.performClick(AppCompatSpinner.java:436)
at com.facebook.accountkit.ui.AccountKitSpinner.performClick(AccountKitSpinner.java:61)
at android.view.View$PerformClick.run(View.java:17660)
at android.os.Handler.handleCallback(Handler.java:800)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5433)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:924)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:691)
at dalvik.system.NativeStart.main(Native Method)
I have no clue what is going on. Please help.
I recently updated my Song Scrapbook app to the latest version and also made sure to update all third-party APIs used by the app. One such third-party tool is the PayPal Android SDK which I use to monetize my app since I live in a country where the Google Wallet Merchant service is currently not supported - which means I cannot use the Play Store in-app or once-off purchase systems in my app.
However, after updating the PayPal SDK to the latest version in my app (via mavenCentral) I get the following error in Android Studio (version: 1.5.1) everytime I want to execute a PayPal transaction:
debug W/paypal.sdk: PayPalService created. API:19 PayPalSDK/PayPal-Android-SDK 2.13.3 (Android 4.4.4; samsung GT-I9060I; )
03-20 16:58:45.540 7804-7804/com.whitsoft.songscrapbook.debug W/ApplicationPackageManager: getCSCPackageItemText()
03-20 16:58:45.550 7804-7804/com.whitsoft.songscrapbook.debug W/ApplicationPackageManager: getCSCPackageItemText()
03-20 16:58:45.550 7804-7804/com.whitsoft.songscrapbook.debug I/dalvikvm: Could not find method com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable, referenced from method com.paypal.android.sdk.at.a
03-20 16:58:45.550 7804-7804/com.whitsoft.songscrapbook.debug W/dalvikvm: VFY: unable to resolve static method 10405: Lcom/google/android/gms/common/GooglePlayServicesUtil;.isGooglePlayServicesAvailable (Landroid/content/Context;)I
03-20 16:58:45.610 7804-7804/com.whitsoft.songscrapbook.debug I/dalvikvm: Could not find method io.card.payment.CardIOActivity.checkSelfPermission, referenced from method io.card.payment.CardIOActivity.onCreate
03-20 16:58:45.610 7804-7804/com.whitsoft.songscrapbook.debug W/dalvikvm: VFY: unable to resolve virtual method 13172: Lio/card/payment/CardIOActivity;.checkSelfPermission (Ljava/lang/String;)I
03-20 16:58:45.820 7804-7843/com.whitsoft.songscrapbook.debug I/System: Loaded time zone names for "en" in 132ms (127ms in ICU)
03-20 16:58:45.840 7804-7804/com.whitsoft.songscrapbook.debug W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0x4168cbc0)
03-20 16:58:45.840 7804-7804/com.whitsoft.songscrapbook.debug E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.whitsoft.songscrapbook.debug, PID: 7804
java.lang.RuntimeException: Unable to start service com.paypal.android.sdk.payments.PayPalService#41e9c5a0 with Intent { cmp=com.whitsoft.songscrapbook.debug/com.paypal.android.sdk.payments.PayPalService (has extras) }: java.lang.IllegalStateException: Unable to extract the trust manager on a.a.k#41ff61a0, sslSocketFactory is class com.paypal.android.sdk.bn
at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2987)
at android.app.ActivityThread.access$2100(ActivityThread.java:166)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1380)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5584)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.IllegalStateException: Unable to extract the trust manager on a.a.k#41ff61a0, sslSocketFactory is class com.paypal.android.sdk.bn
at a.ak.<init>(Unknown Source)
at a.ak.<init>(Unknown Source)
at a.am.b(Unknown Source)
at com.paypal.android.sdk.bt.<init>(Unknown Source)
at com.paypal.android.sdk.payments.PayPalService.a(Unknown Source)
at com.paypal.android.sdk.payments.PayPalService.onStartCommand(Unknown Source)
at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2970)
at android.app.ActivityThread.access$2100(ActivityThread.java:166)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1380)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5584)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
at dalvik.system.NativeStart.main(Native Method)
03-20 17:03:46.103 7804-7804/? I/Process: Sending signal. PID: 7804 SIG: 9
I know this problem is not caused by the device on which I tested the app - as I have tested this app on two very different devices (Samsung Grand Neo and Cubot X15) and both devices produced similar errors. I tried googling the problem to try and solve the problem but after hours of searching found no solution.
Any assistance will be much appreciated.
SilSur.
So it took me roughly 5 hours to figure this one out - which I achieved through a step-by-step elimination of possible causes of the problem.
Turns out the real problem was my haste in trying to update the app. The reason being that the PayPal SDK 2.13.3 version has a new rule in the 'proguard-rules.pro' file that is very important to include:
Rule as follows:
# This is added for okhttp 3.1.2 bug fix as shown at https://github.com/square/okhttp/issues/2323
-keepclassmembers class * implements javax.net.ssl.SSLSocketFactory {
private javax.net.ssl.SSLSocketFactory delegate;
}
This prevents the minify (obfuscation) process of Gradle from removing IMPORTANT code from a previous bug-fix in the PayPal SDK that caused problems with the secure layer socket factory. So yeah - that was the fix: the updated app now works perfectly (just as required).
Lesson learnt: make sure your 'proguard-rules' are exactly as they are suppose to be!
Over & Out, SilSur.
The latest update to the Microsoft Health application appears to have broken backwards compatibility with the SDK preview resulting in errors similar to the following for Android development:
04-28 20:02:09.001 8840-9755/org.hackerforhire.msbandlight E/AndroidRuntime﹕ FATAL EXCEPTION: f
Process: org.hackerforhire.msbandlight, PID: 8840
java.lang.RuntimeException: Parcel android.os.Parcel#1d1d95f2: Unmarshalling unknown type code 40 at offset 368
at android.os.Parcel.readValue(Parcel.java:2228)
at android.os.Parcel.readArrayMapInternal(Parcel.java:2485)
at android.os.BaseBundle.unparcel(BaseBundle.java:221)
at android.os.Bundle.getParcelable(Bundle.java:755)
at com.microsoft.band.f.d(SourceFile:820)
at com.microsoft.band.f.d(SourceFile:40)
at com.microsoft.band.f$d.a(SourceFile:892)
at com.microsoft.band.internal.e$3.handleMessage(SourceFile:137)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at com.microsoft.band.internal.e.run(SourceFile:148)
I previously assumed this was an issue with ProGuard rules per this stack overflow; however, that did not have any impact.
At this point, I'm really looking to see if anyone can suggest a good way to dig into the library JAR and see if there's something I can manually patch to get things working. Is there such a thing or is it best to just hope that Microsoft will release a new SDK soon?
Version information:
Microsoft Health Version: 1.3.10427.2
Microsoft Band SDK Version: 1.3.10215.1
Microsoft Band Firmware Version: 10.2.2810.0 09 R
Android Version: 5.1 (Nexus 6)
UPDATE 2015-04-30: Confirmed that the newest version of the SDK (1.3.10428.1) resolves this issue.
I'm afraid I don't have a solution, but can confirm the problem. I have hit the same problem today. My Xamarin.Forms Android build interfacing to Microsoft Band was working fine yesterday. Now it's dead - the call to BandClient.ConnectTaskAsync() never completes. Even the sample app fails to connect.
My app is using:
Microsoft.Band.Android 1.3.10215.1
Microsoft.Band.Portable 1.0.0.0
I am testing on a Motorola Moto E running Android 4.4.4
using a Microsoft Band with Firmware Version: 10.2.2810.0 09 R
The output from the debugger (from the sample app) follows:
FATAL EXCEPTION: f
Process: Microsoft.Band.Sample, PID: 9382
java.lang.RuntimeException: Parcel android.os.Parcel#4193eec8: Unmarshalling unknown type code 3473459 at offset 344
at android.os.Parcel.readValue(Parcel.java:2080)
at android.os.Parcel.readSparseArrayInternal(Parcel.java:2363)
at android.os.Parcel.readSparseArray(Parcel.java:1735)
at android.os.Parcel.readValue(Parcel.java:2070)
at android.os.Parcel.readArrayMapInternal(Parcel.java:2313)
at android.os.Bundle.unparcel(Bundle.java:249)
at android.os.Bundle.getParcelable(Bundle.java:1206)
at com.microsoft.band.f.d(SourceFile:820)
at com.microsoft.band.f.d(SourceFile:40)
at com.microsoft.band.f$d.a(SourceFile:892)
at com.microsoft.band.internal.e$3.handleMessage(SourceFile:137)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at com.microsoft.band.internal.e.run(SourceFile:148)
CURRENT freed 23K, 17% free 36752K/43852K, paused 4ms+23ms, total 113ms
Activity microsoft.band.sample.MainActivity has leaked ServiceConnection com.microsoft.band.f$1#41aa1438 that was originally bound here
android.app.ServiceConnectionLeaked: Activity microsoft.band.sample.MainActivity has leaked ServiceConnection com.microsoft.band.f$1#41aa1438 that was originally bound here
at com.micros04-29 17:21:27.607 E/ActivityThread( 9382): at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:979)
at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:873)
at android.app.ContextImpl.bindServiceCommon(ContextImpl.java:1690)
at android.app.ContextImpl.bindService(ContextImpl.java:1673)
at android.content.ContextWrapper.bindService(ContextWrapper.java:517)
at com.microsoft.band.f.f(SourceFile:330)
at com.microsoft.band.a.connect(SourceFile:106)
at mono.android.view.View_OnClickListenerImplementor.n_onClick(Native Method)
at mono.android.view.View_OnClickListenerImplementor.onClick(View_OnClickListenerImplementor.java:29)
at android.view.View.performClick(View.java:4456)
at android.view.View$PerformClick.run(View.java:18465)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5086)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
I'm getting a crash always when I install or uninstall an app that use Sync Service, like Facebook, whatsup, etc.
"Unfortunately, Exchange Services has stopped."
I don't know why, but it just happens for some devices, in my case all of then are Android 4.4.2.
First I thought it's my app's fault, but it doesn't make sense once I uninstall my app and the problem continues happening for others apps.
Do you know something about it?
Thank you.
02-07 14:31:49.864 3015-3015/? E/ActivityThread﹕ Failed to find provider info for com.google.android.email.provider
02-07 14:31:49.864 3015-3015/? E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.google.android.exchange, PID: 3015
java.lang.RuntimeException: Unable to create application com.android.exchange.Exchange: java.lang.IllegalArgumentException: Unknown URI content://com.google.android.email.provider
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4347)
at android.app.ActivityThread.access$1500(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.IllegalArgumentException: Unknown URI content://com.google.android.email.provider
at android.content.ContentResolver.call(ContentResolver.java:1352)
at com.android.exchange.Exchange.onCreate(Exchange.java:34)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1007)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4344)
at android.app.ActivityThread.access$1500(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
I found what was happening!
The problem occurs by device when there are sync accounts registered, but the Exchange Service cannot find any application to answer the URI, in my case it was "content://com.google.android.email.provider", to fix it I checked my disable applications and there was it, my default email application was disable. I just enable it again and the problem never occurs again.
Go to Settings > Apps > ALL> Exchange Services > Clear Cache and try opening it. When it opens, check once.
I had that problem. now I’m using a good app called Mailwise. it’s a free email app, very convenient for businesses, you can easily set up multiple email accounts, and it works great with Exchange.
https://play.google.com/store/apps/details?id=com.syntomo.email&hl=en