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

标签 android

我正在尝试在我的 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/

相关文章:

android - 如何使用 AudioManager.STREAM_VOICE_CALL 更改通话音量

android - 从 Android 上的 Facebook SDK 获取配置文件数据始终返回 Null。为什么?

Android DialogFragment 标题未显示

java - 生成的 android 项目中缺少 gradlew

android - 我的 Android JNI JPEG 编码器真的很慢

android - 带有Gradle的Android Jacoco测试带有compileDebugSources和compileDebugTestSources的dependsOn顺序

android - 如何在按下主页按钮后继续录制?

java - Android:并发后台作业的设计(Service、IntentService 还是 AsyncTask?)

android - 使用Google Analytics和odfuscation时生成错误

android - 如何在 android 中使用 Admob 和 phonegap