3

I need send some data from firefox extension to native android application. How can I use intent for this? Is it an api in firefox for this action? Thanks

izumeroot
  • 496
  • 5
  • 12

2 Answers2

3

This is now possible using as an example the code in this add-on

Its done in a very neat way using JNI to access the Android intents Java classes via Firefoxes C++ code.

Maks
  • 7,562
  • 6
  • 43
  • 65
  • 1
    Struggling with the section "hacky way to get activity context" in the add-on main.js code (causes firefox mobile crash). What is the reason? – Mmh Aug 08 '14 at 05:50
  • This is super cool, do you have any other work based on this Maks or @mmh to share? – yatg Jul 10 '15 at 16:46
  • Heres a copy paste example that works: https://github.com/mozilla/firefox-for-android-addons/blob/355f9a01464a0794c1084e8fdbab92c58503f49a/snippets/jni.js#L23-L44 – Noitidart Jul 11 '15 at 09:33
1

I don't think you can. Firefox for Android consists of two parts: the Gecko browser engine (native binary, same as for the desktop Firefox) and the Java-based user interface (Android-specific). The two parts are largely independent and communicate via messaging. Extensions run in Gecko, only the Java-based part can use intents however. I looked at the messages that these two parts can exchange and they are all very specific and related to particular browser actions, nothing that would allow using a generic intent.

If the native application is already running you might be able to communicate via TCP sockets. Either the extension or the native application would need to open a server socket on a well-known port that the other party would connect to.

Community
  • 1
  • 1
Wladimir Palant
  • 56,865
  • 12
  • 98
  • 126
  • Thanks! Is there ability send data in command line params? For example, I will send my data like this - `target_programm my_data_sting` Will it work if android application started already? – izumeroot Oct 09 '12 at 13:51
  • @izumeroot: Don't know, try it? Starting a process should work on Android exactly the same as on desktop. What happens if you start a second instance of your application normally depends on your application - it needs to find the first instance and communicate back to it. – Wladimir Palant Oct 09 '12 at 14:00
  • A communication with first instance i can do via sockets also? Then I don't see sence in command line param. – izumeroot Oct 09 '12 at 14:12