简体   繁体   English

如何使用phonegap插件从android调用javascript函数

[英]how to call javascript function from android using phonegap plugin

This is my index.html 这是我的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. 因此,每当我重新启动手机时,此接收器应该在index.html中调用javascript中的call()方法。 Using Phonegap plugin , im 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. 使用Phonegap插件,我能够从index.html.But调用java方法,在这种情况下,我需要从这个接收器类调用javascript中的方法。 Thank you for your future help. 感谢您将来的帮助。 Please help to resolve this issue.This is urgent guys. 请帮忙解决这个问题。这是紧急的家伙。

There are more then one way to do so, to call the java script function from MainActivity is 有多种方法可以实现,从MainActivity调用java脚本函数是

this.sendJavascript("appResumed");

Here appResumed is javascript function name. 这里的appResumed是javascript函数名。

你会在这里得到正确的答案

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM