How to provide two links for mobile and tablet in webview?

I have two links, for example, for example: facebook.com and m.facebook.com. If this is an Android mobile device, I want

Open m.facebook.com. If it is an Android tablet, I want to open facebook.com link. I want to do in

webview. How is this possible?

+4
source share
2 answers

Here is another solution using simple flag :

Set the boolean value in the file to a specific value, for example say ( res/values-xlarge/ ):

 <resources> <bool name="isTabletDevice">true</bool> </resources> 

Then in the "standard" file of value, for example say ( res/values/ ):

 <resources> <bool name="isTabletDevice">false</bool> </resources> 

Then from your activity select this flag value to check device type :

 boolean tabletDeviceSize = getResources().getBoolean(R.bool.isTabletDevice); if (tabletDeviceSize) { //use tablet link } else { //use mobile link } 

Thanks.

+5
source

Try it, it can help you.

 public static boolean isTablet(Context context) { boolean xlarge = ((context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == 4); boolean large = ((context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_LARGE); return (xlarge || large); } if(isTablet(context)) { //use tablet link } else { //use mobile link. } 
+1
source

All Articles