最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

java - how to call javascript function from android using phonegap plugin- Stack Overflow

programmeradmin2浏览0评论

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 .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 pleted");

    //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.

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 .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 pleted");

    //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.

Share Improve this question edited Aug 6, 2012 at 11:56 Vignesh Prabhu asked Jul 30, 2012 at 6:08 Vignesh PrabhuVignesh Prabhu 591 silver badge7 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 3

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.

you will get the right answer here

发布评论

评论列表(0)

  1. 暂无评论