JavaScriptInterface()不是在Android平台 [英] JavaScriptInterface() is not working in android

查看:114
本文介绍了JavaScriptInterface()不是在Android平台的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我参考以下链接的 HTTP://$c$c.google.com/intl/en/apis/maps/articles/android_v3.html#why

我拿出放了同一code,但是当我改变了HTML code这样的,

i got out put for the same code, but when i changed the html code like this,

这是我的HTML code

<!DOCTYPE html>
 <html>
<head> 
<meta name="viewport" content="initial-scale=1.0, user-scalable=no"/> 
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/> 
<title>Google Maps JavaScript API v3 Example: Directions Simple</title> 
<link href="http://code.google.com/apis/maps/documentation/javascript/examples/default.css" rel="stylesheet" type="text/css" /> 
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script> 
<script type="text/javascript"> 

var directionDisplay;
var directionsService = new google.maps.DirectionsService();
var map;

function initialize() {
    directionsDisplay = new google.maps.DirectionsRenderer();
    var chicago = new google.maps.LatLng(41.850033, -87.6500523);
    var myOptions = {
      zoom:7,
      mapTypeId: google.maps.MapTypeId.ROADMAP,
      center: chicago
    }
    map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
    directionsDisplay.setMap(map);
}

function calcRoute() {
    var start ;
    var end ;
    if (window.android){
      start= window.android.getsource();
     end = window.android.getdestination();
    }
    var request = {
        origin:start, 
        destination:end,
        travelMode: google.maps.DirectionsTravelMode.DRIVING
    };
    directionsService.route(request, function(response, status) {
    if (status == google.maps.DirectionsStatus.OK) {
        directionsDisplay.setDirections(response);
    }
 });
}
</script> 
</head> 
<body onload="initialize()"> 
<div> 
<input id="latlng" type="textbox" value="Chicago"> 
<input id="latlng1" type="textbox" value="Kingman">
</div> 
<div> 
<input type="button" value="Get Route" onclick="calcRoute()"> 
</div> 

<div id="map_canvas"></div> 
</body> 
</html>

这里是我的Andr​​oid code

package com.example.test;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;

import android.app.Activity;
import android.content.Context;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Toast;

public class tset extends Activity {
private static final String MAP_URL = "http://192.168.1.119:81/fulfed1.html";
  private WebView webView;

     public static String disp;
  @Override
  /** Called when the activity is first created. */
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);



    webView = (WebView) findViewById(R.id.webview);
    webView.getSettings().setJavaScriptEnabled(true);
    //Wait for the page to load then send the location information
    webView.setWebViewClient(new WebViewClient());
    webView.loadUrl(MAP_URL);
    /** Allows JavaScript calls to access application resources **/
    webView.addJavascriptInterface(new JavaScriptInterface(), "android");
    this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
  }
  /** Sets up the WebView object and loads the URL of the page **/
  public class JavaScriptInterface
  {
    public String getsource(){
        return "Washington";
    }
    public String getdestination(){
        return  "Newyork";
    }
    }
  }

我没有在点击获取路线按钮,在我的html code越来越路线方向,请大家帮帮忙有什么错我的code。

i am not getting route direction upon click on "Get route" button in my html code,please help what's wrong in my code.

推荐答案

我找到了答案,其实我已经转换成ASCII字符串....

I found the answer, actually i have converted ascii to string....

这篇关于JavaScriptInterface()不是在Android平台的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆