Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/181.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java WebView=网页不可用_Java_Android_Eclipse_Webview_Android Webview - Fatal编程技术网

Java WebView=网页不可用

Java WebView=网页不可用,java,android,eclipse,webview,android-webview,Java,Android,Eclipse,Webview,Android Webview,我正在尝试使用webView显示设备上而不是internet上的HTML文件。我的html文件在/Download文件夹中。启动应用程序时,出现以下错误: 网页不可用 网页file:///storage/sdcard0/Download/manuals/test/index4.html 可能暂时关闭,或者可能已永久移动到新的web地址 我知道文件在那里,但它不会显示它 这是我的密码: package com.asstechmanuals.techmanual; import java.io.F

我正在尝试使用webView显示设备上而不是internet上的HTML文件。我的html文件在/Download文件夹中。启动应用程序时,出现以下错误:

网页不可用

网页file:///storage/sdcard0/Download/manuals/test/index4.html 可能暂时关闭,或者可能已永久移动到新的web地址

我知道文件在那里,但它不会显示它

这是我的密码:

package com.asstechmanuals.techmanual;

import java.io.File;

import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.Window;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class MainActivity extends Activity {

private WebView mWebView;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);


  mWebView =  (WebView) findViewById(R.id.webview);
  mWebView.getSettings().setJavaScriptEnabled(true);




File fileStandard = new File("/storage/sdcard0/Download/manuals/test/index4.html");
File fileNewStandard = new        File("/storage/sdcard0/Download/manuals/test/index4.html");
File fileKitKat = new File("/storage/sdcard0/Download/manuals/test/index4.html");


  if(fileStandard.exists())      
      mWebView.loadUrl("file:///storage/sdcard0/Download/manuals/test/index4.html");
  else if(fileNewStandard.exists()) 
      mWebView.loadUrl("file:///storage/sdcard0/Download/manuals/test/index4.html");
  else if(fileKitKat.exists()) 
      mWebView.loadUrl("file:///storage/sdcard0/Download/manuals/test/index4.html");
  else
      mWebView.loadUrl("file:///storage/sdcard0/Download/manuals/test/index4.html");

  mWebView.setWebViewClient(new vwClient());

}


private class vwClient extends WebViewClient{

   @Override
   public boolean shouldOverrideUrlLoading(WebView webview, String url)
   {
        webview.loadUrl(url);

        if (url.toLowerCase().contains(".pdf"))
        {

            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setDataAndType(Uri.parse(url), "application/pdf");
            startActivity(intent);

        }


        return true;
   }
}

@Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{
   if ((keyCode == KeyEvent.KEYCODE_BACK) && mWebView.canGoBack())
   {
       mWebView.goBack();
       return true;
   }
   return super.onKeyDown(keyCode, event);
}
 @Override
 public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

}

在清单xml文件中,确保您有权为应用程序读取该文件夹,并有权使用internet,即使您实际上没有,但它仍然是必需的

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
可能重复的