datalogic / datalogic-android-sdk

Datalogic Android SDK
12 stars 6 forks source link

Can't capture intents broadcasted by Intent Wedge #3

Open rits-development opened 5 years ago

rits-development commented 5 years ago

I'm trying to capture the intents broadcasted by the Intent Wedge which is enabled. However, my BroadcastReceiver isn't triggered.

I checked the general system LogCat output and noticed the following when I trigger a scan:

2019-09-11 18:08:18.429 2255-2342/? W/ContextImpl: Calling a method in the system process without a qualified user: android.app.ContextImpl.sendBroadcast:966 android.content.ContextWrapper.sendBroadcast:437 com.datalogic.provider.IntentWedgeThread$1.handleMessage:97 android.os.Handler.dispatchMessage:106 android.os.Looper.loop:164 
2019-09-11 18:08:18.431 749-2665/? E/ActivityManager: Sending non-protected broadcast com.datalogic.decodewedge.decode_action from system 2255:com.datalogic.service/1000 pkg com.datalogic.service
    java.lang.Throwable
        at com.android.server.am.ActivityManagerService.checkBroadcastFromSystem(ActivityManagerService.java:19283)
        at com.android.server.am.ActivityManagerService.broadcastIntentLocked(ActivityManagerService.java:19900)
        at com.android.server.am.ActivityManagerService.broadcastIntent(ActivityManagerService.java:20042)
        at android.app.IActivityManager$Stub.onTransact(IActivityManager.java:240)
        at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:2971)
        at android.os.Binder.execTransact(Binder.java:706)

It seems as if Android is dismissing the intent because it's not protected which might explain why my BroadcastReceiver isn't being triggered.

Any idea?

Any help is highly appreciated!

Extra system info

mpennasilico commented 5 years ago

Hi!

I suppose that your App is registering for receiving the Intent Wedge in the Manifest. Please, confirm it to have a complete understanding of the problem.

Anyway, Google introduced several limitations regarding Broadcast from Android 8, in order to improve dispatching performance. I strongly suggest to have a look here https://developer.android.com/about/versions/oreo/background#broadcasts. This could be very helpful to understand if your App is aligned to Android indications regarding this topic.

According to the Android documentation: “_Android 8.0 (API level 26) makes these limitations more stringent.

So, if your App registers itself for receiving the Intent Wedge in the Manifest, this approach works properly until Android 7. But instead, this feature will work as expected for all Android versions, If the App follows the new Google indication regarding the broadcast limitations, introduced by Android 8, that is to register the App to receive intents at runtime with the Context.registerReceiver() call.

Please, report us if this fixes your issue.

laquint53 commented 3 years ago

Hi I have the same issue...how did you solved it ?? Regards

codybrookshear commented 3 years ago

Hi @laquint53, If you `"register the App to receive intents at runtime with the Context.registerReceiver() call", this should allow you to receive barcode data in an intent correctly.

Here are some sample apps that demonstrate calling registerReceiver():

DecodeIntent - Java DecodeIntent - Kotlin

For example, here the line in the Java example where registerReceiver() is called: https://github.com/datalogic/android-samples-astudio/blob/master/Java/DecodeIntent/app/src/main/java/com/datalogic/examples/decodeintent/IntentWedgeSample.java#L76

And as a best practice, unregisterReciver() should be called as well: https://github.com/datalogic/android-samples-astudio/blob/master/Java/DecodeIntent/app/src/main/java/com/datalogic/examples/decodeintent/IntentWedgeSample.java#L85

laquint53 commented 3 years ago

hi @codybrookshear Thanks for the reply, for the oser manufacturer (zebra, bluebird...) the code bellow works, i use a ScanReceiver to receive barcode date in an intent. For Datalogic it doesn't work...I prefer not use nugget package.

here my code :

private ScanReceiver _ScanReceiver; private IntentFilter _ScanFilter;

protected override void OnCreate(Bundle savedInstanceState) {

_ScanReceiver = new ScanReceiver(); _ScanFilter = new IntentFilter("com.datalogic.decodewedge.decode_action") _ScanFilter.AddCategory("com.datalogic.decodewedge.decode_category"); RegisterReceiver(_ScanReceiver, _ScanFilter); }

internal class ScanReceiver : BroadcastReceiver { public override void OnReceive(Context context, Intent intent) { if (intent?.Action == "com.datalogic.decodewedge.decode_category" //DataLogic { codebarre = intent.GetStringExtra("com.datalogic.decode.intentwedge.barcode_string");
appService.OnScanReceived(this, codebarre, null, null); }

        }

}

codybrookshear commented 3 years ago

Ok, it's good to know you are doing Xamarin development. Even if you don't want to utilize our NuGet package ("Datalogic Xamarin SDK"), taking a look at our DecodeIntent sample app could be useful.

This sample only uses the Datalogic Xamarin SDK to configure the IntentWedge feature based on which of the 2 radio boxes are selected.

To avoid needing to use the Datalogic Xamarin SDK altogether, the IntentWedge settings could be configured ahead of time, for instance using the Settings app on the device (Settings > Datalogic Settings > Scanner Settings > Wedge > Intent wedge). Intent wedge is diabled by default. Other ways to configure this include using OEMConfig via an EMM/MDM or using Scan2Deploy Studio.