how to call javascript function from android using phonegap plugin

随声附和 提交于 2019-12-29 09:20:10

问题


This is my index.html

<!DOCTYPE HTML>
<html>
  <head>
    <title>PhoneGap</title>
    <script type="text/javascript" charset="utf-8" src="cordova-1.7.0rc1.js"></script>      
    <script type="text/javascript" charset="utf-8">

    function call(){
      console.log("ANDROID");
    }
    </script>

</head>
<body >
</body>
</html>

This is my receiver class

package com.example.jsfrmjv;
import org.apache.cordova.DroidGap;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

public class BootReciver extends BroadcastReceiver {
Context ctx;
@Override
public void onReceive(Context context, Intent intent) {
    // TODO Auto-generated method stub
    System.out.println("BBBBOOOOOOOOOOTTTTTTT COMPLETED");
    Log.d("ALARM STRIKE", "Reboot completed");

    //Pluginjava pl = new Pluginjava();
        //((DroidGap) this.ctx).sendJavascript("javascript:call()");                
}   
}

So, Whenever i restart my phone , this receiver should call the call() method in javascript in index.html. Using Phonegap plugin , i m able to call the java method from index.html.But in this case , i need to call a method in javascript from this receiver class. Thank you for your future help. Please help to resolve this issue.This is urgent guys.


回答1:


There are more then one way to do so, to call the java script function from MainActivity is

this.sendJavascript("appResumed");

Here appResumed is javascript function name.




回答2:


you will get the right answer here



来源:https://stackoverflow.com/questions/11716167/how-to-call-javascript-function-from-android-using-phonegap-plugin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!