Add permission to access the Internet in the manifest. Without this, your application will not be able to access Internet services.
<manifest xlmns:android...> ... <uses-permission android:name="android.permission.INTERNET" /> <application ... </manifest>
Edited -
In android M and above, you should ask the user for permission at runtime. Before calling
new HttpThread("https://m.baidu.com/",webView,handler).start();
run this code to grant permissions -
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (checkSelfPermission(Manifest.permission.INTERNET) != PackageManager.PERMISSION_GRANTED) { // Should we show an explanation? if (shouldShowRequestPermissionRationale( Manifest.permission.INTERNET)) { // Explain to the user why we need to read the contacts } requestPermissions(new String[]{Manifest.permission.INTERNET}, 1); // MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE is an // app-defined int constant return; }else { new HttpThread("https://m.baidu.com/",webView,handler).start(); } }else { new HttpThread("https://m.baidu.com/",webView,handler).start(); }
And override this method -
@Override public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) { switch (requestCode) { case 1: { // If request is cancelled, the result arrays are empty. if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { // permission was granted, yay! Do the // contacts-related task you need to do. new HttpThread("https://m.baidu.com/",webView,handler).start(); } else { // permission denied, boo! Disable the // functionality that depends on this permission. Snackbar.make(parent, "Click on allow to Access Internet in you application", Snackbar.LENGTH_LONG) .setAction("CLOSE", new View.OnClickListener() { @Override public void onClick(View view) { } }) .setActionTextColor(getResources().getColor(android.R.color.holo_purple )).show(); } return; } // other 'case' lines to check for other // permissions this app might request } }
After that, it should work on your Android M phone as well. I hope this works.