I'm trying to integrate ZXing's barcode scanner into a MonoDroid application. I see that normal Android (java) apps have IntentIntegration.java and IntentResult.java to include into their project to help. I was wondering if anyone has ported those to .NET (I didn't see them ported in the csharp project.)? I'm also wondering if anyone has implemented ZXing in another way to get to work with their app? If anyone has integrated with MonoDroid, what needs to be done to initiate a scan in a button click handler?
Also, if anyone has any other 3 party barcode scanner that could be implemented instead, put those suggestions in the comments.
We now have
ZXing
ports forMonoTouch
andMonodroid
. https://github.com/Redth/ZXing.Net.MobileThe first question is, do you actually need to port those files? :-)
You can include Java source code into a Mono for Android project; just set the Build action to
AndroidJavaSource
and the source will be compiled into the resulting .apk. This can also be done with.jar
files.Then comes the question of invoking the Java code from C#.
In the case of
IntentIntegration.java
andIntentResult.java
, that may be enough, as those types don't support inheritance (they'refinal
). Granted, using JNIEnv to invoke methods on them would be a PITA, but it can be done:Furthermore, the
IntentIntegrator
docs mention that the Activity provided must override the Activity.OnActivityResult method.All that said, porting
IntentIntegrator.java
shouldn't be that difficult, as most of it is a wrapper over Activity.StartActivityForResult with an appropriate intent and construction of anAlertDialog
(which you may or may not need).