Start a new topic

Communication between Javascript and Android

Communication between Javascript and Android


Done! The process to call Android method from JavaScript is:

1.- Your activity must implement the method of the interface 'ArchitectUrlListener'.

2.- In that method (urlWasInvoked) you get the data as Bartosz described.

3.- From Javascript you just call that method with something like this: document.location = "architectsdk://metodoEnAndroid?param1=10&param2=20";

 

I suppose this will be usefull for more people!

1 person likes this

Hello.

I'd like to know how I can call an Activity method from javascript (with parameters).

Thank you very much in advance.

Try something like this:

 

JavaScript:

function runMethod()

{

   document.location = "architectsdk://runMethod?param1="+value1+"&param2="+value2;  

}

 

Android:


@Override

public boolean urlWasInvoked(String url) {

//parsing the retrieved url string

List<NameValuePair> queryParams = URLEncodedUtils.parse(URI.create(url), "UTF-8");

 

String param1 = "";

String param2 = "";

// getting the values of the contained GET-parameters

for(NameValuePair pair : queryParams)

{

   if(pair.getName().equals("param1"))

   {

      param1 = pair.getValue();

   }

   if(pair.getName().equals("param2"))

   {

      param2 = pair.getValue();

   }

}

 

//run method with parameters

myMethod(param1,param2);

return true;

}

Thank you very much! 

I'll try the code and then I'll tell you if it worked.
Login or Signup to post a comment