Tengo un viewpager de paginas web. Es muy sencillo y funciona bien. Pero al pulsar el enlace de llamada href="tel:971142254">
, intenta acceder a pagina web y me da error. He probado con esto, pero me da el mismo error.
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;
}
Os dejo el codigo. Gracias y un saludo.
public class Comercio2 extends FragmentActivity{
ViewPager pager;
FragmentStatePagerAdapter adapter;
/* Just some random URLs
*
* Each page of our pager will display one URL from this array
* Swiping, to the right will take you to the next page having
* the next URL.
*/
String[] toVisit={
"http://www.angoher2.com/alimenta1b.html",
"http://www.angoher2.com/alimenta2b.html",
"http://www.angoher2.com/alimenta3b.html",
};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.comercio2);
pager=(ViewPager)findViewById(R.id.container2);
TabLayout container_tab2 = (TabLayout) findViewById(R.id.container_tab2);
container_tab2.setupWithViewPager(pager, true);
adapter=new FragmentStatePagerAdapter(getSupportFragmentManager()){
@Override
public int getCount() {
// This makes sure getItem doesn't use a position
// that is out of bounds of our array of URLs
return toVisit.length;
}
@Override
public Fragment getItem(int position) {
// Here is where all the magic of the adapter happens
// As you can see, this is really simple.
return Fragment_Web.newInstance(toVisit[position]);
}
};
//Let the pager know which adapter it is supposed to use
pager.setAdapter(adapter);
}
}
Este es el fragment.
public class Fragment_Web extends Fragment{
WebView browser;
String url;
@Override
public View onCreateView(LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
View view=inflater.inflate(R.layout.fragment_web, container, false);
browser=(WebView)view.findViewById(R.id.my_browser);
browser.setWebViewClient(new WebViewClient());
browser.loadUrl(url);
return view;
}
// This is the method the pager adapter will use
// to create a new fragment
public static Fragment newInstance(String url){
Fragment_Web f = new Fragment_Web();
f.url = url;
return f;
}
}