如果你想使用startActivityForResult,你必须获得壁虎的主要活动。此代码未经测试,但请检查一下:
function genMethodSIG(aParamsArr, aRet) {
// aParamsArr is an array of SIG's for each param. Not fully qualified name, meaning if its a class, it needs the surrouning L and ;
// aRet is a SIG for the return value. Not fully qualified name, same meaning as above row
return '(' + (aParamsArr ? aParamsArr.join('') : '') + ')' + aRet;
}
function fullyQualifiedNameOfClass(aClass) {
// aClass is a string with L and ; arround it
return aClass.substr(1, aClass - 2);
}
// (SIG\.[a-z]*?)\.substr\(1, SIG\.[a-z]*?\.length - 2\) // fullyQualifiedNameOfClass\($1\)
var my_jenv = null;
try {
my_jenv = JNI.GetForThread();
//////////////// start - declares
var SIG = {
Activity: 'Landroid/app/Activity;', // java.lang.Object -> android.content.Context -> android.content.ContextWrapper -> android.view.ContextThemeWrapper -> android.app.Activity // http://developer.android.com/reference/android/app/Activity.html
Context: 'Landroid/content/Context;', // java.lang.Object -> android.content.Context // http://developer.android.com/reference/android/content/Context.html
GeckoAppShell: 'Lorg/mozilla/gecko/GeckoAppShell;', // https://dxr.mozilla.org/mozilla-central/source/mobile/android/base/Makefile.in#296
GeckoInterface: 'Lorg/mozilla/gecko/GeckoAppShell$GeckoInterface;', // https://dxr.mozilla.org/mozilla-central/source/mobile/android/base/java/org/mozilla/gecko/GeckoApp.java#125-131
Intent: 'Landroid/content/Intent;', // java.lang.Object -> android.content.Intent // http://developer.android.com/reference/android/content/Intent.html
String: 'Ljava/lang/String;',
int: 'I',
void: 'V'
};
var Activity = JNI.LoadClass(my_jenv, fullyQualifiedNameOfClass(SIG.Activity), {
methods: [
{
/* http://developer.android.com/reference/android/app/Activity.html#startActivityForResult%28android.content.Intent,%20int%29
* public void startActivityForResult (Intent intent, int requestCode)
*/
name: 'startActivityForResult',
sig: genMethodSIG([
SIG.Intent, // intent
SIG.int // requestCode
],
SIG.void // return
)
}
]
});
var Context = JNI.LoadClass(my_jenv, fullyQualifiedNameOfClass(SIG.Context), {
methods: [
{
/* http://developer.android.com/reference/android/content/Context.html#startActivity%28android.content.Intent%29
* public abstract void startActivity (Intent intent)
*/
name: 'startActivity',
sig: genMethodSIG([
SIG.Intent // intent
],
SIG.void // return
)
}
]
});
var GeckoAppShell = JNI.LoadClass(my_jenv, fullyQualifiedNameOfClass(SIG.GeckoAppShell), {
static_methods: [
{
/* https://dxr.mozilla.org/mozilla-central/source/mobile/android/base/java/org/mozilla/gecko/GeckoAppShell.java#2144
* public static Context getContext()
*/
name: 'getContext',
sig: genMethodSIG(
null, // no parameters
SIG.Context // return
)
},
{
/* https://dxr.mozilla.org/mozilla-central/source/mobile/android/base/java/org/mozilla/gecko/GeckoAppShell.java#2199
* public static GeckoInterface getGeckoInterface()
*/
name: 'getGeckoInterface',
sig: genMethodSIG(
null, // no parameters
SIG.GeckoInterface // return
)
}
]
});
var GeckoInterface = JNI.LoadClass(my_jenv, fullyQualifiedNameOfClass(SIG.GeckoInterface), {
methods: [
{
/* https://dxr.mozilla.org/mozilla-central/source/mobile/android/base/java/org/mozilla/gecko/BaseGeckoInterface.java#54
* public Activity getActivity()
*/
name: 'getActivity',
sig: genMethodSIG(
null, // no parameters
SIG.Activity // return
)
}
]
});
var Intent = JNI.LoadClass(my_jenv, fullyQualifiedNameOfClass(SIG.Intent), {
constructors: [ // i think all constructors return void and have name '<init>'
{
/* http://developer.android.com/reference/android/content/Intent.html#Intent%28java.lang.String%29
* public Intent (String action)
*/
// name: '<init>', // not necessary
sig: genMethodSIG([
SIG.String // action
],
SIG.void // return
)
}
],
methods: [
{
/* http://developer.android.com/reference/android/content/Context.html#startActivity%28android.content.Intent%29
* public abstract void startActivity (Intent intent)
*/
name: 'startActivity',
sig: genMethodSIG([
SIG.Intent // intent
],
SIG.void // return
)
}
]
});
//////////////// end - declares
//////////////// start - my code
// var cContext = GeckoAppShell.getContext();
var cGeckoInterface = GeckoAppShell.getGeckoInterface();
var cGeckoMainActivity = cGeckoInterface.getActivity();
var cIntent = Intent['new']('my.example.app'); // i dont know your intent action string, its up to you
var cRequestCode = 1; // i dont know what code you want to use here, its up to you
cGeckoMainActivity.startActivityForResult(cIntent, cRequestCode);
//////////////// end - my code
} finally {
if (my_jenv) {
JNI.UnloadClasses(my_jenv);
}
}