Wikitude
play_for_work
Forum
FAQ
Documentation
Download
wikitude.com
How can we help you today?
Enter your search term here...
Search
Start a new topic
Discussions
Wikitude SDK (Android, iOS, UWP)
Wikitude SDK Questions or Problems
Communication between Javascript and Android
S
Santiago González
started a topic
over 9 years ago
Communication between Javascript and Android
4 Comments
Oldest First
Popular
Newest First
Sorted by
Oldest First
S
Santiago González
said
over 9 years ago
Hello.
I'd like to know how I can call an Activity method from javascript (with parameters).
Thank you very much in advance.
B
Bartosz Gregorczyk
said
over 9 years ago
Try something like this:
JavaScript:
function runMethod()
{
document.location = "architectsdk://runMethod?param1="+value1+"¶m2="+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;
}
S
Santiago González
said
over 9 years ago
Thank you very much!
I'll try the code and then I'll tell you if it worked.
S
Santiago González
said
over 9 years ago
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¶m2=20";
I suppose this will be usefull for more people!
1 person likes this
Login
or
Signup
to post a comment
More topics in
Wikitude SDK Questions or Problems
Instatiation of WTArchitectView compile errors
Point of interest - native iOS
Slider
Camera lagging / slow in native Swift application
Create a web service
N-th ImageDrawable not displayed
Radar Example
stop defaultlocationmanager and use architectview.injectlocation ios 10
WTC Size Limit
AngularJS and wikitude
See all 3869 topics
© 2021 Wikitude, a Qualcomm company
Santiago González