Ad
How To Open Dialerapp In Android From Webview
I have this code in my mainactivity.java file:
package com.business.i13bubbles;
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.content.Intent;
public class MainActivity extends AppCompatActivity {
private WebView MywebView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
MywebView = (WebView) findViewById(R.id.view2);
WebSettings webSettings = MywebView.getSettings();
webSettings.setJavaScriptEnabled(true);
MywebView.loadUrl("http://www.13bubbles.com");
MywebView.setWebViewClient(new WebViewClient());
}
@Override
public void onBackPressed() {
if (MywebView.canGoBack()) {
MywebView.goBack();
} else {
super.onBackPressed();
}
}
public boolean shouldOverrideUrlLoading(WebView view2, String url) {
if (url.startsWith("tel:")) {
Intent intent = new Intent(Intent.ACTION_DIAL);
intent.setData(Uri.parse("tel:123"));
startActivity(intent);
} else if (url.startsWith("http:") || url.startsWith("https:")) {
view2.loadUrl(url); }
return true;
}
}
I get no errors here. There is a link on the site:
<a target="_blank" rel="nofollow noreferrer" href="tel:+919910673876" class="btn btn-border-filled">Call @ 9910 6738 76</a>
It doesn't open the dialer app. Am I doing something wrong ??? I have been trying to fix this since morning but couldn't do anything.
Ad
Answer
Use this code in your shouldOverrideUrlLoading()
method:
public boolean shouldOverrideUrlLoading(WebView view2, String url) {
if (url.contains("tel:")) {
Intent intent = new Intent(Intent.ACTION_DIAL);
intent.setData(Uri.parse(url))
startActivity(intent);
return true;
}
}
Ad
source: stackoverflow.com
Related Questions
- → should I choose reactjs+f7 or f7+vue.js?
- → Phonegap Android write to sd card
- → Local reference jquery script in nanohttpd (Android)
- → Click to navigate on mobile devices
- → How to allow api access to android or ios app only(laravel)?
- → Access the Camera and CameraRoll on Android using React Native?
- → React native change listening port
- → What is the default unit of style in React Native?
- → Google play market autocomplete icon
- → Warning: Each child in an array or iterator should have a unique "key" prop. Check the render method of `ListView`
- → Using Laravel with Genymotion
- → react native using like web-based ajax function
- → react native pdf View
Ad