简体   繁体   English

WebView Android中未以HTML格式加载图像

[英]Image is not loading for html format in webview android

Have created a functionality when user clicks on the image thumbnail, the main image will load by calling on the WebView.loadurl(String.format()) method, the selected image will then be uploaded and displayed for the user to view. 当用户单击图像缩略图时已创建了功能,将通过调用WebView.loadurl(String.format())方法加载主图像,然后将所选图像上传并显示给用户查看。 However, in this instances, when user clicks on the image thumbnail, the following message is displayed: 但是,在这种情况下,当用户单击图像缩略图时,将显示以下消息:

The requested URL /projectname_uat/data/images/property/property_id/360/1/index.htm is not found on this server. 在此服务器上找不到请求的URL /projectname_uat/data/images/property/property_id/360/1/index.htm。

What has gone wrong in that instances? 在那种情况下出了什么问题?

Furthermore, when I copied the following url into a web browser: Google Chrome, it wasn't showing initially, however when I made the following changes, the images was showing in the web browser but not on the app device. 此外,当我将以下网址复制到Web浏览器中时:Google Chrome,最初并未显示,但是当我进行以下更改时,图像显示在Web浏览器中,而不显示在应用程序设备上。 What I do understand is that there is no difference between htm or html, and most the images that can be displayed are either in htm or html. 我真正理解的是,htm或html之间没有区别,并且大多数可以显示的图像都是htm或html。

the following change that I have made, which is to change htm to html: 我所做的以下更改是将htm更改为html:

/projectname_uat/data/images/property/property_id/360/1/index. / projectname_uat /数据/图像/属性/ PROPERTY_ID / 360/1 /索引。 html HTML

Could anyone offer any assistance to this issue?? 任何人都可以为这个问题提供任何帮助吗? It has been bogging my mind for a couple of days and it is getting frustrating. 这几天一直困扰着我,令人沮丧。 Thanks in advance. 提前致谢。

Code: 码:

int img_id = 1;
photoPb = (ProgressBar) findViewById(R.id.photoPb);
    photoPb.setVisibility(View.INVISIBLE);
    webView = (WebView) findViewById(R.id.webview01);
    webView.getSettings().setJavaScriptEnabled(true);
    //webView.getSettings().setPluginsEnabled(true);
    webView.getSettings().setPluginState(PluginState.ON);
    webView.setVerticalScrollBarEnabled(false);
    webView.setHorizontalScrollBarEnabled(false);
    webView.setWebViewClient(new WebViewClient() {
        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
            Toast.makeText(getContext(), description, Toast.LENGTH_SHORT).show();
        }
    });
 if (panoSize > 0) {
        g = (Gallery) findViewById(R.id.gallery01);
        g.setAdapter(new ImageAdapter());
        int pad = 15;
        g.setSpacing(1);
        g.setUnselectedAlpha(255);
        g.setPadding(pad, 10, pad, pad);
        g.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
                img_id = position;
                setImageShade(position);
                captionText.setText(caption[position]);
                Log.i("PropertyPanoramaActvity:if(panoSize>0)","******webView.loadUrl******"+getString(R.string.app_360_domain)+getString(R.string.app_360_property)+(getIntent().getIntExtra("propertyId", 0))+getString(R.string.app_360_directory)+(img_id)+getString(R.string.app_360_index));
                //webView.loadUrl(String.format("https://developer.dapoltd.com/spacetobe_uat/data/images/property/property107/360/4/index.htm", id, img_id));
                webView.loadUrl(String.format(getString(R.string.app_360_domain)+getString(R.string.app_360_property)+(getIntent().getIntExtra("propertyId", 0))+getString(R.string.app_360_directory)+(img_id)+getString(R.string.app_360_index)));


            }
        });
    }

String.XML: String.XML:

<string name="app_360_domain">https://developer.dapoltd.com/spacetobe_uat/</string>
<string name="app_360_property">data/images/property/property</string>
<string name="app_360_directory">/360/</string>
<string name="app_360_index">/index.htm</string>

您没有将app_360_index字符串值更改为/index.html

尝试使用:

webView.loadUrl( ""+getString(R.string.app_360_domain)+getString(R.string.app_360_property)+(getIntent().getIntExtra("propertyId", 0))+getString(R.string.app_360_directory)+(img_id++)+getString(R.string.app_360_index));

It is really hard to say why it is not showing image, but what I think now is the problem me be in back slashes. 真的很难说为什么它不显示图像,但是我现在想的是我正处于反斜杠的问题。 Try this: 尝试这个:

1) 1)

String urlToLoad = String.format(getString(R.string.app_360_domain) + getString(R.string.app_360_property)+(getIntent().getIntExtra("propertyId", 0))+getString(R.string.app_360_directory)+(img_id)+getString(R.string.app_360_index);

2) Then go to debug, and check urlToLoad value if it is opened in browser. 2)然后去调试,并检查urlToLoad值是否在浏览器中打开。 3) If not '@' must be added at the start of url in order compiler understood that backslash is part of the url, not escape sign 3)如果不是'@'必须在url的开头添加,以使编译器理解反斜杠是url的一部分,而不是转义符

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM