1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
|
package com.tnt.driver;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Toast;
import android.net.ConnectivityManager;
import android.net.Uri;
public class MainActivitygo extends Activity {
private Context mContext;
@SuppressLint("SetJavaScriptEnabled")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_go);
mContext = getApplicationContext();
String url="http://tnt.com/driver/fr/";
WebView wv=(WebView)findViewById(R.id.webView1);
wv.setWebViewClient(new WebViewClient());
wv.getSettings().getJavaScriptEnabled();
wv.getSettings().setJavaScriptEnabled(true);
wv.getSettings().setLoadsImagesAutomatically(true);
wv.addJavascriptInterface(url, ACCESSIBILITY_SERVICE);
wv.canGoBackOrForward(0);
wv.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
ConnectivityManager cm=(ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
@SuppressWarnings("unused")
boolean online;
if(cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).isAvailable() ||
cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI).isAvailable()){
wv.loadUrl(url);
Toast.makeText(getApplicationContext(), "Verification connexion internet", Toast.LENGTH_LONG).show();
// Set the web view client
wv.setWebViewClient(new WebViewClient(){
// For level bellow 24
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url){
Toast.makeText(mContext, "GetDrivers",Toast.LENGTH_SHORT).show();
if(url.startsWith("http")){
Toast.makeText(mContext,"patientez...",Toast.LENGTH_SHORT).show();
// Return false means, web view will handle the link
return false;
}else if(url.startsWith("tel:")){
// Handle the link
handleTelLink1(url);
// Return true means, leave the current web view and handle the itself
return true;
}
return false;
}
// From level 24
});
wv.loadUrl(url);
}
else{
Toast.makeText(getApplicationContext(), "GetDrivers n'a pas de connexion", Toast.LENGTH_LONG).show();
}
}
protected void handleTelLink1(String url) {
// TODO Auto-generated method stub
Intent intent = new Intent(Intent.ACTION_DIAL);
// Send phone number to intent as data
intent.setData(Uri.parse(url));
startActivity(intent);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
protected void handleTelLink(String url){
// Initialize an intent to open dialer with specified phone number
// It open the dialer and allow user to call the number manually
Intent intent = new Intent(Intent.ACTION_DIAL);
// Send phone number to intent as data
intent.setData(Uri.parse(url));
// Start the dialer activity with number
startActivity(intent);
}
} |
Partager