package com.example.t2noob;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.Toast;
public class Activity extends Activity
{
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url.startsWith("tel:")) {
Intent intent = new Intent(Intent.ACTION_DIAL,
Uri.parse(url));
startActivity(intent);
}else if(url.startsWith("http:") || url.startsWith("https:")) {
view.loadUrl(url);
}
return true;
}
WebView mWebView;
public void onCreate(Bundle paramBundle)
{
super.onCreate(paramBundle);
requestWindowFeature(1);
getWindow().setFlags(1024, 1024);
setContentView(2130903040);
final Button button = (Button) findViewById(R.id.Home);//BUTTONS ON TOP OF WEBVIEW. HOME
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
mWebView.loadUrl("test.com");
}
});
final Button button1 = (Button) findViewById(R.id.Back);//BUTTONS ON TOP OF WEBVIEW. BACK
button1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
mWebView.goBack();
}
});
this.mWebView = ((WebView)findViewById(2131034112));
this.mWebView.getSettings().setJavaScriptEnabled(true);
this.mWebView.setWebViewClient(new WebViewClient());
this.mWebView.getSettings().setJavaScriptEnabled(true);
this.mWebView.setVerticalScrollBarEnabled(true);
this.mWebView.setHorizontalScrollBarEnabled(true);
this.mWebView.loadUrl("test.com");
this.mWebView.getSettings().setLoadWithOverviewMode(true);
}
public boolean onKeyDown(int paramInt, KeyEvent paramKeyEvent)//LETS USER PUSH BACK BUTTON ON PHONE TO GO BACK A PAGE IN WEBVIEW.
{
boolean bool;
if ((paramInt != 4) || (!this.mWebView.canGoBack()))
{
bool = super.onKeyDown(paramInt, paramKeyEvent);
}
else
{
this.mWebView.goBack();
bool = true;
}
return bool;
}
}
So i have the above source code the function shoudOverrideUrlLoading
should catch both the web links to open them in the webview if I didn’t misread
and open phone numbers with the android dialer.
with the above code i can get links to open in the webview but it wont open the numbers in the dialer.
If i add this code to the program.
private static final WebViewClient Webview = null;
this.mWebView.setWebViewClient(Webview);
I can get the dialer to open but then the web links wont open in the webview but will actually open in the default browser.
So i would like some help in how to get it to open phone numbers in the dialer and web links in the webview and not just have either or.
Use this
}
And set the web view client as
This will make sure the links are opened in the same web view, and not the browser.
Note : Remove all other uses of setWebViewClient()
Edited : This will solve!