zxing融入monodroid应用 [英] zxing integration into monodroid app

查看:153
本文介绍了zxing融入monodroid应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想ZXing的酒吧code扫描仪集成到MonoDroid应用程序。我看到,正常的Andr​​oid(Java)的应用程序都<一href="http://$c$c.google.com/p/zxing/source/browse/trunk/android-integration/src/com/google/zxing/#zxing/integration/android">IntentIntegration.java和IntentResult.java 中要加入到他们的项目提供帮助。我想知道是否有人已经移植那些.NET(我没有看到他们在CSHARP项目移植。)?我也想知道是否有人已经实施ZXing以另一种方式来获得他们的应用程序来工作吗?如果任何人有MonoDroid集成,需要做的事情,以启动扫描的按钮单击处理程序是什么?

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?

此外,如果任何人有可能被实现,而不是任何其他3方棒code扫描仪,放在评论这些建议。

Also, if anyone has any other 3 party barcode scanner that could be implemented instead, put those suggestions in the comments.

推荐答案

第一个问题是,你真的需要移植这些文件? : - )

The first question is, do you actually need to port those files? :-)

您可以包括Java源代码code到一个单声道的Andr​​oid项目;只需设置生成操作 AndroidJavaSource 和源将被编译到生成的.apk文件。这也可以用的.jar 文件完成的。

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.

然后是从C#调用Java code的问题。

Then comes the question of invoking the Java code from C#.

在的情况下, IntentIntegration.java IntentResult.java ,那的可以的是不够的,因为这些类型不支持继承(他们是最后)。当然,使用 JNIEnv的来调用它们的方法将是一个皮塔饼,但它可以做到:

In the case of IntentIntegration.java and IntentResult.java, that may be enough, as those types don't support inheritance (they're final). Granted, using JNIEnv to invoke methods on them would be a PITA, but it can be done:

// Untested code, provided for demo purposes:

// Handle of the Java class we're invoking
IntPtr IntentResult = 
        JNIEnv.FindClass("com/google/zxing/integration/android/IntentIntegrator");
// Handle of the method to invoke
IntPtr IntentResult_initiateScan = 
        JNIEnv.GetMethodID(IntentResult, "initiateScan", 
            "(Landroid/app/Activity;)Landroid/app/AlertDialog;");
            // method signature can be obtained from `javap -s`
// Invoke the method; return value is an AlertDialog instance
IntPtr rAlertDialog = JNIEnv.CallStaticObjectMethod (
        IntentResult, IntentResult_initiateScan, new JValue (someActivity));
// ...and construct a nice managed wrapper over the Java instance.
AlertDialog alertDialog = new AlertDialog (rAlertDialog);

此外, IntentIntegrator 文档提到,所提供的活动必须重写<一href="http://docs.mono-android.net/index.aspx?link=M%3aAndroid.App.Activity.OnActivityResult(System.Int32%2cAndroid.App.Result%2cAndroid.Content.Intent)"相对=nofollow> Activity.OnActivityResult 方法。

Furthermore, the IntentIntegrator docs mention that the Activity provided must override the Activity.OnActivityResult method.

所有这一切说,移植 IntentIntegrator.java 不应该的的困难,因为大部分是包装过<一个href="http://docs.mono-android.net/index.aspx?link=M%3aAndroid.App.Activity.StartActivityForResult(Android.Content.Intent%2cSystem.Int32)"相对=nofollow> Activity.StartActivityForResult 与适当的意图,并建设一个 AlertDialog (您可能会或可能不需要)。

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 an AlertDialog (which you may or may not need).

这篇关于zxing融入monodroid应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆