当前位置: 动力学知识库 > 问答 > 编程问答 >

eclipse - Net is not working inside my android program

问题描述:

I made a simple web browser with WebView, and I set it to load google, but it's like it doesn't even know there is some Wifi connection on my phone. without even trying to load it says "Webpage not available".

It doesn't even load "192.168.1.1" which is modem configuration.

My question is should I use any special code for it to be able to use my wifi or not? (my wifi is already connected and works with Firefox or Chrome)

Tnx.

Edit: Here's the whole code of the program, not much.

import java.net.NetPermission;

import android.app.Activity;

import android.content.DialogInterface.OnClickListener;

import android.os.Bundle;

import android.provider.ContactsContract.CommonDataKinds.Website;

import android.support.annotation.IdRes;

import android.view.Menu;

import android.view.MenuItem;

import android.view.View;

import android.webkit.WebView;

import android.widget.Button;

public class MainActivity extends Activity {

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

WebView wv = (WebView)findViewById(R.id.webView1);

wv = (WebView) findViewById(R.id.webView1);

wv.loadUrl("192.168.1.1");

}

@Override

public boolean onCreateOptionsMenu(Menu menu) {

// Inflate the menu; this adds items to the action bar if it is present.

getMenuInflater().inflate(R.menu.main, menu);

return true;

}

@Override

public boolean onOptionsItemSelected(MenuItem item) {

// Handle action bar item clicks here. The action bar will

// automatically handle clicks on the Home/Up button, so long

// as you specify a parent activity in AndroidManifest.xml.

int id = item.getItemId();

if (id == R.id.action_settings) {

return true;

}

return super.onOptionsItemSelected(item);

}

}

网友答案:

Make sure you require the Internet permission in your AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.android"
          android:versionCode="1"
          android:versionName="1.0">
    <uses-sdk android:minSdkVersion="17"/>

    <uses-permission android:name="android.permission.INTERNET" />

    <application android:label="@string/app_name" android:icon="@drawable/ic_launcher">
        <!-- Activities go here -->
    </application>
</manifest>
分享给朋友:
您可能感兴趣的文章:
随机阅读: