Start a new topic

Passing data from Activity to JS

Hi, 

I'm very new to Wikitude API.
Just wondering how could I pass my data (from my MainActivity) to Javascript so it could use it to filter the results that it obtained from the database and use it to load the POI accordingly.  

Please provide a detail guidance as I'm really new in this. 

Thanks in advance. 


I use WIkitude SDK 6.1 because my minimum sdk app is 16.

Hello Jacob,


Can you pass data from MainActivity.java to JavaScript? I have no idea to do that. I have  JSON data in my MainActivity.java. I want to pass it from MainActivity.java to JavaScript.

[{"id":"1","longitude":"106.81104507297277","latitude":"-6.580994179643144","description":"Melayani pembuatan jus dan sop buah asli dan segar.","name":"Jus dan Sop Buah Kabita"},
{"id":"2","longitude":"106.81095656007528","latitude":"-6.5810284855365735","description":"Melayani kerusakan ringan hingga berat","name":"Tambal Ban Melky Guslow"},
{"id":"3","longitude":"106.81095890700819","latitude":"-6.580837638157673","description":"Menyediakan jasa fotocopy, laminating dan jilid.","name":"Kantik Fotocopy"},
{"id":"4","longitude":"106.81141287088394","latitude":"-6.581399521941143","description":"Jasa Benkel motor terpercaya, proritas kami adalah kepuasan pelanggan.","name":"Bintang Motor"},
{"id":"5","longitude":"106.788322","latitude":"-6.558250","description":"Toko Makanan Alami.","name":"Angkringan 107"},
{"id":"6","longitude":"106.792338","latitude":"-6.556606","description":"Jasa Isi Ulang Air Galon.","name":"Depot Air Cahaya RO"},
{"id":"7","longitude":"106.807548","latitude":"-6.560975","description":"Tempat kecantikan anda.","name":"Kartika Make Up"},
{"id":"8","longitude":"-6.567786","latitude":"106.793692","description":"Membersihkan motor anda dengan cermat.","name":"Steam Motor Indri"}]

 

Can you give me an example. Thanks

Hello Jacob,

There are a couple of errors in your code. First of all, since the calls are asynchronous in javascript, it could be that you are calling the callJavascript method before the loading of the index.html file is completed. Therefore, I would suggest you move the callJavascript method outside of the onPostCreate (maybe put it in the onArchitect World loaded function). Second of all, make sure that the LadUserFromJsonData is actually a function inside the World, otherwise the line below is wrong
loadUserFromJsonData: function loadUserFromJsonDataFn(userData) {
Thanks
Eva
I have tried but still unable to pass data
My AR Activity
@Override
protected void onPostCreate(Bundle savedInstanceState){
super.onPostCreate(savedInstanceState);

architectView.onPostCreate();
try{
final JSONArray jsonArray = generateUserInformation(LoginActivity.user);
this.architectView.load("file:///android_asset/detail/index.html");
this.architectView.callJavascript("World.loadUserFromJsonData(" + jsonArray.toString() + ")");
} catch (Exception e){

}
} My Javascript
loadUserFromJsonData: function loadUserFromJsonDataFn(userData) {
var user = userData.user;
}
Hello Jacob,

Please have a look at the documentation here.

Thanks
Eva

 

Login or Signup to post a comment