【问题标题】:how to call javascript function from android using phonegap plugin如何使用phonegap插件从android调用javascript函数
【发布时间】:2012-07-27 19:21:00
【问题描述】:

这是我的 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()");                
}   
}

所以,每当我重新启动手机时,这个接收器应该在 index.html 中的 javascript 中调用 call() 方法。使用 Phonegap 插件,我可以从 index.html 调用 java 方法。但在这种情况下,我需要从这个接收器类调用 javascript 中的方法。感谢您对未来的帮助。请帮助解决这个问题。这是紧急的家伙。

【问题讨论】:

    标签: java javascript android cordova call


    【解决方案1】:

    这样做的方法不止一种,从MainActivity调用java脚本函数是

    this.sendJavascript("appResumed");
    

    这里的 appResumed 是 javascript 函数名。

    【讨论】:

    • 嘿@Rajnikant,你能告诉我这个appResumed 函数应该在哪个JS 中。在index.jsplugin JS 文件中。因为我无法使用sendJavascript() 调用JS 方法,但是当我编写类似sendJavascript("alert(Hello')") 的语句时。所以,请告诉我如何实现这一目标。谢谢
    【解决方案2】:

    你会得到正确答案here

    【讨论】:

    • 此功能没有利用 phonegap 功能。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多