Android WebView未使用INTERNET权限
我有一个简单的应用程序,我不能让WebView显示google.com 没有错误,但EditText上没有显示任何内容 我已经添加了互联网许可,但它不起作用 这是我的舱单Android WebView未使用INTERNET权限,android,Android,我有一个简单的应用程序,我不能让WebView显示google.com 没有错误,但EditText上没有显示任何内容 我已经添加了互联网许可,但它不起作用 这是我的舱单 <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.taxihelperforcustomer" and
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.taxihelperforcustomer"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="16" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.taxihelperforcustomer.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
LogCat上没有错误或消息。
我正在我的设备上测试此代码。您不应该从主线程访问网络。使用AsyncTask执行访问。您没有
WebView
。您尝试了什么?例如,您是否尝试过调试,并在代码执行过程中看到发生了什么?您是否尝试添加日志语句以查看正在执行的代码行以及在流程的不同步骤中得到的结果类型?是否希望在webview中显示url。?。选中webview加载URL链接中的edit 2。我的问题错了。不是webview,只是想在我访问特定url(如www.google.com)时读取客户端上的所有文字。
EditText mResult;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mResult = (EditText)findViewById(R.id.result);
Button btn = (Button)findViewById(R.id.sendBtn);
btn.setOnClickListener(new Button.OnClickListener(){
public void onClick(View v) {
// TODO Auto-generated method stub
String html = DownloadHtml("http://www.google.com");
try{
mResult.setText(html);
} catch(HTMLException e) {
Toast.makeText(v.getContext(), e.getMessage(), Toast.LENGTH_LONG).show();
}
}
});
}
public String DownloadHtml(String addr){
StringBuilder googleHtml = new StringBuilder();
try{
URL url = new URL(addr);
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
if(conn != null){
conn.setConnectTimeout(10000);
conn.setUseCaches(false);
if(conn.getResponseCode() == HttpURLConnection.HTTP_OK){
BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream(), "EUC-KR"));
for(;;)
{
String line = br.readLine();
if(line == null)
break;
googleHtml.append(line + "\n");
}
br.close();
}
conn.disconnect();
}
} catch(Exception ex){
Toast.makeText(this, ex.getMessage(), Toast.LENGTH_LONG).show();
}
return googleHtml.toString();
}