I have an application in android, made in phonegap, running in the background. I would like to bring it to the foreground after a javascript verification. I found this link (Communication between Android Java and Phonegap Javascript? ), Where i can call the method in java without problems.
I'm trying to change it to suit my needs. But isnt working.
Below is what I got so far:
Class Main:
public class HiveTaxi extends DroidGap {
private PhoneNumber mc;
@Override public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.init();
mc = new PhoneNumber(this, appView);
appView.addJavascriptInterface(mc, "MyPhone");
super.loadUrl(Config.getStartUrl());
}
//other code....
Class PhoneNumber:
public class PhoneNumber
{
private WebView mAppView;
private DroidGap mGap;
public PhoneNumber(DroidGap gap, WebView view)
{
mAppView = view;
mGap = gap;
}
@JavascriptInterface
public void getTelephoneNumber(Context context)
{
Intent it = new Intent("android.intent.action");
it.setComponent(new ComponentName(context.getPackageName(), HiveTaxi.class.getName()));
it.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.getApplicationContext().startActivity(it);
}
}
JS File (line 491)
window.MyPhone.getTelephoneNumber();
Error:
03-09 18:55:52.939 32758-32758/com.projeto.hivetaxi D/CordovaLog﹕ file:///android_asset/www/js/functions.js: Line 491 : Uncaught Error: Error calling method on NPObject. 03-09 18:55:52.939 32758-32758/com.projeto.hivetaxi I/chromium﹕ [INFO:CONSOLE(491)] "Uncaught Error: Error calling method on NPObject.", source: file:///android_asset/www/js/functions.js (491)