gpt4 book ai didi

android - 在 Android WebView 中使用 Weinre 进行调试

转载 作者:行者123 更新时间:2023-11-29 14:15:37 27 4
gpt4 key购买 nike

我正在尝试在我的 Android 应用程序中调试 WebView。我做了一些研究,发现 weinre 非常有用。我使用的是 PhoneGap 的 weinre PhoneGap Debugging Tool.
然而,让我感到困惑的是,它只有在我使用它在 native 浏览器中进行调试时才能正常运行,而不是在我打开我的应用程序时运行良好。当我打开我的应用程序时,它没有显示 webview 供我检查。

有人知道如何让它与 webview 一起工作吗?或者我必须在本地安装 Weinre 才能运行?

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button button = (Button)this.findViewById(R.id.button1);
this.webview = (WebView)this.findViewById(R.id.webView1);
webview.setWebChromeClient(new WebChromeClient());


final String htmlPre = "<!DOCTYPE html><html lang=\"en\"><head><meta charset=\"utf-8\"> <script src='http://172.16.0.135:8080/target/target-script-min.js#anonymous'></script> <script>alert('hello')</script></head><body style='margin:0; pading:0; background-color: black;'>";
final String htmlCode =
" <embed style='width:100%; height:100%' src='http://www.platipus.nl/flvplayer/download/1.0/FLVPlayer.swf?fullscreen=true&video=http://www.platipus.nl/flvplayer/download/pl-600.flv&autoplay=true' " +
" autoplay='true' " +
" quality='high' bgcolor='#000000' " +
" name='VideoPlayer' align='middle'" + // width='640' height='480'
" allowScriptAccess='*' allowFullScreen='true'" +
" type='application/x-shockwave-flash' " +
" pluginspage='http://www.macromedia.com/go/getflashplayer' />" +
"";
final String htmlPost = "</body></html>";

this.webview.getSettings().setJavaScriptEnabled(true);
button.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
webview.loadDataWithBaseURL("null", htmlPre+htmlCode+htmlPost, "text/html", "UTF-8", null);
}
});
Now I'm trying something new like this and it does not work anymore, any suggestion? Thanks :)

最佳答案

我在我的开发笔记本电脑 (debian) 上安装了 weinre,并且在任何浏览器和 Android webview 中都能正常工作。

就像用node.js安装weinre一样简单:

sudo npm -g install weinre

documentation 中的文档

最后一个提示:启动服务器时记得更改

--boundHost [hostname | ip address | -all-]

如果您的服务器不在本地主机上。

关于android - 在 Android WebView 中使用 Weinre 进行调试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16683403/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com