1. 程式人生 > >接入滴滴打車html5 網頁版

接入滴滴打車html5 網頁版

使用webview載入html5

由於涉及定位功能

if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION)
                != PackageManager.PERMISSION_GRANTED
                || ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)
                != PackageManager.PERMISSION_GRANTED
                || ActivityCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)
                != PackageManager.PERMISSION_GRANTED) {
            Toast.makeText(getApplicationContext(),"沒有許可權,請手動開啟定位許可權",Toast.LENGTH_SHORT).show();
            ActivityCompat.requestPermissions(MainActivity.this,new String[]{Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.WRITE_EXTERNAL_STORAGE}, 100);
            return false;
   }


開啟許可權之後,webView開啟地理位置功能

 

WebView webView = (WebView)findViewById(R.id.webview);  
WebSettings webSettings = webView.getSettings();  
webSettings.setJavaScriptEnabled(true);  
webSettings.setDatabaseEnabled(true);      
String dir = this.getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath();   
webSettings.setGeolocationDatabasePath(dir);       

webSettings.setGeolocationEnabled(true);    //啟用地理定位  
  
webSettings.setDomStorageEnabled(true)    
webView.setWebChromeClient(new WebChromeClient() {  
  @Override  
  public void onReceivedIcon(WebView view, Bitmap icon) {  
     super.onReceivedIcon(view, icon);  
  
}  
  
@Override  
public void onGeolocationPermissionsShowPrompt(String origin,Callback callback) {  
  callback.invoke(origin, true, false);    
  super.onGeolocationPermissionsShowPrompt(origin, callback);  
  
}  
});

使用webView載入滴滴打車的網頁地址:

https://common.diditaxi.com.cn/general/webEntry?wx=true&bizid=257&channel=70365

使用安卓手機可以正常使用滴滴打車