如何在没有外部应用程序的情况下显示来自 URL 的文档?

How to display documents from URL without external app?

在我的应用程序中,我正在获取文档的 URL,我想在我的应用程序中显示它们,而不是在任何外部应用程序中。

这是我用过的代码。

public class Doc_webview extends Activity implements AdvancedWebView.Listener{
    private AdvancedWebView mWebView;
String tag="doc";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_doc_webview);
        mWebView = (AdvancedWebView) findViewById(R.id.webview);
        //mWebView.setListener(this, this);
        Intent intent=getIntent();
        Log.e(tag,"url "+Uri.parse(intent.getStringExtra("URL")).toString());
        mWebView.setListener(this, this);
        mWebView.loadUrl("http://docs.google.com/gview?embedded=true&url="+Uri.parse(intent.getStringExtra("URL")).toString());

    }
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
        super.onActivityResult(requestCode, resultCode, intent);
        mWebView.onActivityResult(requestCode, resultCode, intent);
        // ...
    }

    @Override
    public void onPageStarted(String url, Bitmap favicon) {
        Log.e(tag,"page started "+url);
    }

    @Override
    public void onPageFinished(String url) {
        Log.e(tag,"page finished "+url);
    }

    @Override
    public void onPageError(int errorCode, String description, String failingUrl) {
        Log.e(tag,"page error "+description);
    }

    @Override
    public void onDownloadRequested(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) {
        Log.e(tag,"download started "+url);
    }

    @Override
    public void onExternalPageRequest(String url) {
        Log.e(tag,"page request "+url);
    }
}

我只想显示它们,而不是打开它们进行编辑。

好吧,我正在使用这段代码在我的网络视图中打开一个文档

    public class ToSite extends Activity {

    WebView webView;

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

        Utils.setShared(this);
        String url = getIntent().getExtras().getString("url");

        System.out.println(url);

        if (!URLUtil.isValidUrl(url)) {
            finish();
            Toast.makeText(this, "URL not Valid", Toast.LENGTH_LONG).show();
        }
        webView = (WebView) findViewById(R.id.webview);
        webView.setWebViewClient(new MyBrowser());

        webView.getSettings().setLoadsImagesAutomatically(true);
        webView.getSettings().setJavaScriptEnabled(true);
        webView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
        webView.loadUrl(url);
    }

    private class MyBrowser extends WebViewClient {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;
        }
    }
}

我的 url 是

http://docs.google.com/gview?embedded=true&url=http://52.24.60.37/guilt/uploads/termcondition/profile60252550.pdf

Google 文档 URL : http://docs.google.com/gview?embedded=true&url=\

我的文档 URL : http://52.24.60.37/guilt/uploads/termcondition/profile60252550.pdf

附加 URL 以在 WebView 中打开文档