简体   繁体   English

无法打开从URL下载到Android模拟器上的doc或docx文件

[英]Unable to open doc or docx files downloaded from URL onto android emulator

I'm looking to securely download or view PDF and android files within an app from a URL. 我正在寻找从URL安全下载或查看应用内的PDF和android文件的方法。 I'm successfully able to download and open PDF files by using the DownloadManager or opening an intent with a URI as the argument. 通过使用DownloadManager或使用URI作为参数打开意图,我可以成功下载并打开PDF文件。 The same code will download a doc or docx file, but when I try to open the doc \\ docx file on the android emulator (directly from downloads), I get "can't open file". 相同的代码将下载一个doc或docx文件,但是当我尝试在android仿真器上直接打开doc \\ docx文件时(直接从下载中),我得到“无法打开文件”。

This is the code that opens an intent and downloads the docx \\ doc file: 这是打开一个意图并下载docx \\ doc文件的代码:

public void openWebPage(String url) {
    Uri webpage = Uri.parse(url);
    Intent intent = new Intent(Intent.ACTION_VIEW, webpage);

    if (intent.resolveActivity(getPackageManager()) != null) {
        startActivity(intent);
    }
}

Do you know why I am unable to open these doc \\ docx files? 您知道为什么我无法打开这些doc \\ docx文件吗?

Do you have an app that can display *.doc / *.docx files? 您是否有一个可以显示* .doc / * .docx文件的应用程序? If so, there might be a problem similar to what CommonsWare pointed out in his comment, or with the proper registration of the app so that it "reacts" properly to your intent. 如果是这样,则可能存在与CommonsWare在他的评论中指出的问题相似的问题,或者存在与应用程序的正确注册相似的问题,从而可以正确地“响应”您的意图。

If you don't have an app on your emulator to display this kind of file, this means there is no application registered for your particular intent, which in turn means that it fails, eg says "can't open file". 如果您的模拟器上没有用于显示此类文件的应用程序,则意味着没有针对您的特定意图注册的应用程序,这反过来意味着该应用程序失败,例如说“无法打开文件”。

This is the normal and expected behaviour in case no app is registered for opening this type of file. 如果没有注册任何应用程序打开此类型的文件,这是正常且预期的行为。

If you do have an app to open Microsoft Word documents, maybe try to reinstall it, which might fix any problems you might have. 如果您确实有打开Microsoft Word文档的应用程序,则可以尝试重新安装它,这可能会解决您可能遇到的任何问题。

So, in the end it comes down to installing / reinstalling an app to view *.doc / *.docx files. 因此,最后归结为安装/重新安装应用程序以查看* .doc / * .docx文件。 There are countless viewers for Microsoft Windows documents in the app store. 在应用商店中,有无数的Microsoft Windows文档查看器。 So if you are able to access the Play Store from within your emulator, go ahead :) 因此,如果您能够从模拟器中访问Play商店,请继续:)

If this still doesn't fix your error, try to further explain your issue, eg which app you used and at which point exactly it fails. 如果仍然不能解决您的错误,请尝试进一步说明您的问题,例如您使用了哪个应用程序,以及在什么时候该应用程序失败了。 As far as I can tell, your intent is fine, you just don't have an app to display whatever kind of document you want to open. 据我所知,您的意图很好,您只是没有应用程序来显示要打开的任何类型的文档。

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

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