gpt4 book ai didi

android - Firefox android 附加组件 intent startActivity 回调

转载 作者:行者123 更新时间:2023-11-30 01:33:32 25 4
gpt4 key购买 nike

我可以按照此处的说明从 Firefox 附加组件运行我的应用程序:https://github.com/cscott/skeleton-addon-fxandroid/blob/jni/bootstrap.js .

我的示例代码是:

let jenv;
try {
jenv = JNI.GetForThread();

let GeckoAppShell = JNI.LoadClass(jenv, "org.mozilla.gecko.GeckoAppShell", {
static_methods: [
{ name: "getContext", sig: "()Landroid/content/Context;" },
],
});
let Intent = JNI.LoadClass(jenv, "android.content.Intent", {
constructors: [
{ name: "<init>", sig: "(Ljava/lang/String;)V" },
],
});
let Context = JNI.LoadClass(jenv, "android.content.Context", {
methods: [
{ name: "startActivity", sig: "(Landroid/content/Intent;)V" },
],
});

let context = GeckoAppShell.getContext();
let intent = Intent["new"]("my.example.app");
context.startActivity(intent);

} finally {
if (jenv) {
JNI.UnloadClasses(jenv);
}
}

JNI.jsm , 我没有找到 startActivityForResult() 的类似物.在我的应用程序中,我生成了一些数据。我怎样才能将它传递回我的附加组件?

我认为唯一的方法是有意识地打开 Firefox。是否可以在我的附加组件中监听 Firefox Intent ?

最佳答案

如果您想使用 startActivityForResult,您必须获取 gecko 主 Activity 。此代码未经测试,但请检查一下:

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);
}
}

关于android - Firefox android 附加组件 intent startActivity 回调,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35414131/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com