WebView - webpage not available

I (like many others) have followed the web browsing guide, but I cannot load pages. It looks like this: "Webpage Unavailable"

I made sure that the emulator has Internet access, and to eliminate the problem with the emulator, I tried to install it on my phone, which led to the same behavior.

I read that the biggest problem is that people do not put the INTERNET permission in my manifest file, which I tried to put as a child of different manifest elements, but to no avail. Does anyone know why I cannot download this?

Here is my code:

Manifest:

 <application android:icon="@drawable/icon" android:label="@string/app_name"> <activity android:name=".AndroidTestActivity" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> <uses-permission android:name="android.permission.INTERNET" /> </activity> </application> </manifest> 

AndroidTestActivity

 public class AndroidTestActivity extends Activity { WebView webview; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); webview = (WebView) findViewById(R.id.webview); webview.getSettings().setJavaScriptEnabled(true); webview.loadUrl("http://www.google.com/m"); Intent intent = getIntent(); // To get the action of the intent use System.out.println(intent.getAction()); // We current open a hard-coded URL try { webview.setWebViewClient(new AndroidTestClient()); } catch (Exception e) { e.printStackTrace(); } } @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if ((keyCode == KeyEvent.KEYCODE_BACK) && webview.canGoBack()) { webview.goBack(); return true; } return super.onKeyDown(keyCode, event); } private class AndroidTestClient extends WebViewClient { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { view.loadUrl(url); return true; } } } 

Thanks!

+6
source share
1 answer

Your Internet permission should be the direct child of the "manifest" - should not be under the "application".

eg.

 <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.mypackage.name" android:installLocation="auto" android:versionCode="3210" android:versionName="1.1.0"> <uses-permission android:name="android.permission.INTERNET" /> <uses-sdk android:minSdkVersion="6" android:targetSdkVersion="10"/> <application android:icon="@drawable/icon" android:label="@string/app_name" android:debuggable="true"> <!-- activities go here --> </application> </manifest> 

Hope this helps -serkan

+21
source

Source: https://habr.com/ru/post/898467/


All Articles