Ваша активность:
/*
* entry point of the application starting the index.html of PhoneGap
* */
package com.test.my.myApp;
import org.apache.cordova.DroidGap;
import android.os.Bundle;
import android.util.Log;
import com.google.analytics.tracking.android.EasyTracker;
public class MyOpelMainActivitiy extends DroidGap
{
String curPhoneNumber;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
super.setIntegerProperty("splashscreen", R.drawable.splash);
super.loadUrl("file:///android_asset/www/app/index.html",15000);
}
@Override
public void onStart() {
super.onStart();
this.appView.addJavascriptInterface(new JsInterface(), "android");
curPhoneNumber = "test";
// The rest of your onStart() code.
EasyTracker.getInstance().activityStart(this); // Add this method.
}
@Override
public void onDestroy()
{
super.onDestroy();
com.google.analytics.tracking.android.EasyTracker.getInstance().activityStop(this);
}
public class JsInterface{
public String getPhoneNumber()
{
// Here call any of the public activity methods....
return curPhoneNumber;
}
}
}
Разметка HTMl:
<script type="text/javascript">
alert(android.getPhoneNumber());
</script>
=============================================== =========================