如何使用PhoneGap的插件调用来自Android的javascript函数如何使用、函数、插件、PhoneGap

2023-09-14 00:03:40 作者:怪我不能满足你

这是我的index.html

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>

这是我的接收器类

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()");                
}   
}

所以,每当我重新启动我的电话,该接收器应该调用call()方法中JavaScript中的index.html。使用PhoneGap的插件,即时通讯能够从index.html.But调用Java方法在这种情况下,我需要从这个接收器类调用javascript的方法。谢谢你的未来帮助。请帮助解决这个issue.This迫切的家伙。

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.

推荐答案

有这样做,调用从 MainActivity 是Java脚本函数是一个以上的方式

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

this.sendJavascript("appResumed");

下面AP presumed是JavaScript函数名。

Here appResumed is javascript function name.