我写了一个简单的程序,可以将网页加载到 WebView 中。
URL 包含 http://并且 web View 工作得很好,除了它仍然通过这个恼人的 107 错误,大多数人说这是因为你的 url 不包含 http header 。
我在网上搜索过,找不到像我这样的情况
06-13 09:12:25.259: W/webcore(656): java.lang.Throwable: EventHub.removeMessages(int what = 107) is not supported before the WebViewCore is set up.
06-13 09:12:25.259: W/webcore(656): at android.webkit.WebViewCore$EventHub.removeMessages(WebViewCore.java:1683)
06-13 09:12:25.259: W/webcore(656): at android.webkit.WebViewCore$EventHub.access$7900(WebViewCore.java:926)
06-13 09:12:25.259: W/webcore(656): at android.webkit.WebViewCore.removeMessages(WebViewCore.java:1795)
06-13 09:12:25.259: W/webcore(656): at android.webkit.WebView.sendOurVisibleRect(WebView.java:2917)
06-13 09:12:25.259: W/webcore(656): at android.webkit.ZoomManager.setZoomScale(ZoomManager.java:593)
06-13 09:12:25.259: W/webcore(656): at android.webkit.ZoomManager.access$1700(ZoomManager.java:49)
06-13 09:12:25.259: W/webcore(656): at android.webkit.ZoomManager$PostScale.run(ZoomManager.java:984)
06-13 09:12:25.259: W/webcore(656): at android.os.Handler.handleCallback(Handler.java:605)
06-13 09:12:25.259: W/webcore(656): at android.os.Handler.dispatchMessage(Handler.java:92)
06-13 09:12:25.259: W/webcore(656): at android.os.Looper.loop(Looper.java:137)
06-13 09:12:25.259: W/webcore(656): at android.app.ActivityThread.main(ActivityThread.java:4424)
06-13 09:12:25.259: W/webcore(656): at java.lang.reflect.Method.invokeNative(Native Method)
06-13 09:12:25.259: W/webcore(656): at java.lang.reflect.Method.invoke(Method.java:511)
06-13 09:12:25.259: W/webcore(656): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
06-13 09:12:25.259: W/webcore(656): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
06-13 09:12:25.259: W/webcore(656): at dalvik.system.NativeStart.main(Native Method)
我的 XML 看起来像:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/navBar"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:orientation="vertical" >
</LinearLayout>
<WebView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/webView"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="6.40" >
</WebView>
</LinearLayout>
我的 java 代码如下所示:
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.LinearLayout;
public class MobileWebView extends Activity{
private WebView myWebView;
final Context context = this; //set the context to be itself
ProgressDialog progressDialog;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.web_view); //set view
//set the webview
myWebView = (WebView) findViewById(R.id.webView);
myWebView.getSettings().setJavaScriptEnabled(true);
//setup and load the progress bar
progressDialog = new ProgressDialog(context);
progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
progressDialog.setMessage("Loading. Please wait...");
myWebView.setWebViewClient(new MyWebViewClient(){
@Override
public void onPageFinished(WebView view, final String url) {
progressDialog.dismiss();
}
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
//make sure dialog is showing
if(! progressDialog.isShowing()){
progressDialog.show();
}
}
});
//get the site url passed from main activity
String urlName = this.getIntent().getExtras().getString("site");
System.out.println(urlName);
myWebView.loadUrl(urlName);
SetupNavBar();
}
private void SetupNavBar(){
//set nav bar
LinearLayout ll = (LinearLayout)findViewById(R.id.navBar);
NavigationBar nb = new NavigationBar(this);
nb.setLeftBarButton("Back");
nb.setBarTitle("Online Doctor");
NavigationBar.NavigationBarListener nbl = new NavigationBar.NavigationBarListener() {
@Override
public void OnNavigationButtonClick(int which) {
//if left button
if(which == 0){
finish();
}
}
};
nb.setNavigationBarListener(nbl);
ll.addView(nb);
}
//override the override loading method for the webview client
private class MyWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if(url.startsWith("http")){
progressDialog.show();
view.loadUrl(url);
return true;
} else {
return false;
}
}
}
}
在我的主类中,我在以下情况下调用它:
final Context context = this; //set the context to be itself
private void setup(){
//assign buttons
Button login = (Button)findViewById(R.id.loginButton);
Button register = (Button)findViewById(R.id.registerButton);
//setup onclick for each button
bindButtonWithVisitWebsite(login, "https://onlinedoctor.lloydspharmacy.com/login");
bindButtonWithVisitWebsite(register,"https://onlinedoctor.lloydspharmacy.com/register");
}
private void bindButtonWithVisitWebsite(Button b, final String urlName){
b.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Bundle bundle = new Bundle();
bundle.putString("site",urlName);
Intent intent = new Intent(context, MobileWebView.class);
intent.putExtras(bundle);
}
});
}
最佳答案
WebSettings settings = webView.getSettings();
settings.setPluginState(PluginState.ON);
这在 ICS 中对我有用。
关于java - Android:当url包含http时,在设置WebViewCore之前不支持removeMessages(int what = 107),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11010939/
是的,我知道最好使用webmock,但我想知道如何在RSpec中模拟此方法:defmethod_to_testurl=URI.parseurireq=Net::HTTP::Post.newurl.pathres=Net::HTTP.start(url.host,url.port)do|http|http.requestreq,foo:1endresend这是RSpec:let(:uri){'http://example.com'}specify'HTTPcall'dohttp=mock:httpNet::HTTP.stub!(:start).and_yieldhttphttp.shou
从给定URL下载文件并立即将其上传到AmazonS3的更直接的方法是什么(+将有关文件的一些信息保存到数据库中,例如名称、大小等)?现在,我既不使用Paperclip,也不使用Carrierwave。谢谢 最佳答案 简单明了:require'open-uri'require's3'amazon=S3::Service.new(access_key_id:'KEY',secret_access_key:'KEY')bucket=amazon.buckets.find('image_storage')url='http://www.ex
我正在编写一个小脚本来定位aws存储桶中的特定文件,并创建一个临时验证的url以发送给同事。(理想情况下,这将创建类似于在控制台上右键单击存储桶中的文件并复制链接地址的结果)。我研究过回形针,它似乎不符合这个标准,但我可能只是不知道它的全部功能。我尝试了以下方法:defauthenticated_url(file_name,bucket)AWS::S3::S3Object.url_for(file_name,bucket,:secure=>true,:expires=>20*60)end产生这种类型的结果:...-1.amazonaws.com/file_path/file.zip.A
我真的很习惯使用Ruby编写以下代码:my_hash={}my_hash['test']=1Java中对应的数据结构是什么? 最佳答案 HashMapmap=newHashMap();map.put("test",1);我假设? 关于java-等价于Java中的RubyHash,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/22737685/
我正在使用Rails构建一个简单的聊天应用程序。当用户输入url时,我希望将其输出为html链接(即“url”)。我想知道在Ruby中是否有任何库或众所周知的方法可以做到这一点。如果没有,我有一些不错的正则表达式示例代码可以使用... 最佳答案 查看auto_linkRails提供的辅助方法。这会将所有URL和电子邮件地址变成可点击的链接(htmlanchor标记)。这是文档中的代码示例。auto_link("Gotohttp://www.rubyonrails.organdsayhellotodavid@loudthinking.
我正在尝试使用boilerpipe来自JRuby。我看过guide从JRuby调用Java,并成功地将它与另一个Java包一起使用,但无法弄清楚为什么同样的东西不能用于boilerpipe。我正在尝试基本上从JRuby中执行与此Java等效的操作:URLurl=newURL("http://www.example.com/some-location/index.html");Stringtext=ArticleExtractor.INSTANCE.getText(url);在JRuby中试过这个:require'java'url=java.net.URL.new("http://www
我目前正在使用以下方法获取页面的源代码:Net::HTTP.get(URI.parse(page.url))我还想获取HTTP状态,而无需发出第二个请求。有没有办法用另一种方法做到这一点?我一直在查看文档,但似乎找不到我要找的东西。 最佳答案 在我看来,除非您需要一些真正的低级访问或控制,否则最好使用Ruby的内置Open::URI模块:require'open-uri'io=open('http://www.example.org/')#=>#body=io.read[0,50]#=>"["200","OK"]io.base_ur
我正在使用RubyonRails3.0.9,我想生成一个传递一些自定义参数的link_toURL。也就是说,有一个articles_path(www.my_web_site_name.com/articles)我想生成如下内容:link_to'Samplelinktitle',...#HereIshouldimplementthecode#=>'http://www.my_web_site_name.com/articles?param1=value1¶m2=value2&...我如何编写link_to语句“alàRubyonRailsWay”以实现该目的?如果我想通过传递一些
我只想对我一直在思考的这个问题有其他意见,例如我有classuser_controller和classuserclassUserattr_accessor:name,:usernameendclassUserController//dosomethingaboutanythingaboutusersend问题是我的User类中是否应该有逻辑user=User.newuser.do_something(user1)oritshouldbeuser_controller=UserController.newuser_controller.do_something(user1,user2)我
什么是ruby的rack或python的Java的wsgi?还有一个路由库。 最佳答案 来自Python标准PEP333:Bycontrast,althoughJavahasjustasmanywebapplicationframeworksavailable,Java's"servlet"APImakesitpossibleforapplicationswrittenwithanyJavawebapplicationframeworktoruninanywebserverthatsupportstheservletAPI.ht