Android 应用程序无法连接到任何东西
正如标题所示,我编写的应用程序(非常简单,应该加载并显示 google.com)似乎无法连接到互联网。
我在 MOTODEV studio 中编写了它,它也不会从模拟器连接,但我在代理后面并且知道会发生这种情况。所以我完成了,自签名 .apk 并将其传输到我的 GT-I5500(三星 Galaxy Europa)。 apk 安装得很好,但无法加载页面。
需要明确的是......手机上的常规浏览器可以很好地加载任何内容,我只是似乎无法从应用程序以编程方式执行此操作。我搜索了这个网站,一堆谷歌点击和android开发演练,但没有找到我的问题的解决方案:(
一些代码:
package com.fooit.skifnews;
import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class Skifnews2Activity extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
WebView webView = new WebView(this);;
webView.setWebChromeClient(new WebChromeClient());
webView.setWebViewClient(new WebViewClient());
webView.getSettings().setJavaScriptEnabled(true);
String url="www.google.com";
webView.loadUrl(url);
setContentView(webView);
}
}
和清单有
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.fooit.skifnews"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="7" />
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<application android:icon="@drawable/icon" android:label="@string/app_name" android:permission="android.permission.INTERNET">
<activity android:name=".Skifnews2Activity"
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>
什么想法为什么这可能不起作用吗?运行时它返回404,这表明我因为 Google 没有关闭,所以我无法退出 -.- 但标准浏览器运行得很好,我省略了一堆像 R.java 这样的文件,因为我实际上还没有在这个简单的应用程序中使用它。 ..我没有无论如何触摸它..但它不包含任何关于 webview 的提及...看不出它应该是一个问题。
Like the title says, the app I've written (very simple, should load and display google.com) can't seem to connect out to the internet.
I wrote it in MOTODEV studio, it wouldn't connect from the emulator either but I was behind a proxy and knew this would happen. So I finished up, self-signed the .apk and transferred it to my GT-I5500 (Samsung galaxy europa). The apk installed just fine, but its not loading the page.
Just to be clear.... the regular browser on the phone loads anything just fine, I just can't seem to do so programatically from an app. I trawled this site, a bunch of Google hits and the android dev walkthroughs and no luck finding a solution my issue:(
Some code:
package com.fooit.skifnews;
import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class Skifnews2Activity extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
WebView webView = new WebView(this);;
webView.setWebChromeClient(new WebChromeClient());
webView.setWebViewClient(new WebViewClient());
webView.getSettings().setJavaScriptEnabled(true);
String url="www.google.com";
webView.loadUrl(url);
setContentView(webView);
}
}
and the manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.fooit.skifnews"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="7" />
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<application android:icon="@drawable/icon" android:label="@string/app_name" android:permission="android.permission.INTERNET">
<activity android:name=".Skifnews2Activity"
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>
Any ideas why this might not be working? When run it returns me 404's which would suggest I'm not getting out since Google isn't down -.- Yet the standard browser gets out just fine. I'm omitting a bunch of files like R.java since I'm not actually using that yet for this simple app.... I haven't touched it anyway.. but it doesn't contain any mention of webview...can't see that it should be a problem.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将其添加到清单中的应用程序标记之前:
Add this to your manifest, before the application tag:
您是否尝试过更改:
到
?
Have you tried changing:
To
?