Skip to content

Instantly share code, notes, and snippets.

@Noitidart
Created July 15, 2015 06:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Noitidart/a67e7556027889070bb6 to your computer and use it in GitHub Desktop.
Save Noitidart/a67e7556027889070bb6 to your computer and use it in GitHub Desktop.
// Opening a preference screen from 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: "(Landroid/content/Context;Ljava/lang/Class;)V" },
],
});
let GeckoPreferences = JNI.LoadClass(jenv, "org.mozilla.gecko.preferences.GeckoPreferences", {
static_methods: [
{ name: "setResourceToOpen", sig: "(Landroid/content/Intent;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"](context, GeckoPreferences);
// preferences_privacy is the resource name for the privacy screen.
// All the preferences resources are defined here:
// http://mxr.mozilla.org/mozilla-central/source/mobile/android/base/resources/xml/
GeckoPreferences.setResourceToOpen(intent, "preferences_privacy");
context.startActivity(intent);
} finally {
if (jenv) {
JNI.UnloadClasses(jenv);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment