最初の質問は、これらのファイルを実際に移植する必要があるかどうかです。:-)
Java ソース コードを Mono for Android プロジェクトに含めることができます。Build アクションを に設定するだけAndroidJavaSource
で、ソースが結果の .apk にコンパイルされます。これは、.jar
ファイルでも実行できます。
次に、C# から Java コードを呼び出す問題が発生します。
IntentIntegration.java
との場合、これらの型は継承をサポートしていないため、それで十分かもしれません (それらはIntentResult.java
です)final
。確かに、 JNIEnvを使用してそれらのメソッドを呼び出すことは PITA になりますが、実行できます。
// 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);
さらに、ドキュメントには、提供されたアクティビティがActivity.OnActivityResultメソッドIntentIntegrator
をオーバーライドする必要があることが記載されています。
とは言っても、移植はそれほど難しくIntentIntegrator.java
ないはずです。ほとんどの場合、 Activity.StartActivityForResultのラッパーであり、適切な意図とAlertDialog
(必要な場合とそうでない場合があります) の構造を備えているからです。