相关疑难解决方法(0)

从url下载pdf然后用pdf阅读器打开它

我正在尝试编写一个应用程序从url下载pdf,将它们存储在sd上,然后由adobe pdf reader或其他能够打开pdf的应用程序打开.

直到现在,我已经"成功下载并将其存储在Sd卡上"(但每当我尝试使用pdf阅读器打开pdf时,阅读器崩溃并发出意外错误),例如,http://maven.apache.组织/ Maven的1.x中/ maven.pdf

这是我的下载程序的代码:

//........code set ui stuff
//........code set ui stuff
     new DownloadFile().execute(fileUrl, fileName); 


private class DownloadFile extends AsyncTask<String, Void, Void>{

        @Override
        protected Void doInBackground(String... strings) {
            String fileUrl = strings[0];   // -> http://maven.apache.org/maven-1.x/maven.pdf
            String fileName = strings[1];  // -> maven.pdf
            String extStorageDirectory = Environment.getExternalStorageDirectory().toString();
            File folder = new File(extStorageDirectory, "testthreepdf");
            folder.mkdir();

            File pdfFile = new File(folder, fileName);

            try{
                pdfFile.createNewFile();
            }catch (IOException e){
                e.printStackTrace();
            }
            FileDownloader.downloadFile(fileUrl, pdfFile);
            return null;
        }
    }



public class FileDownloader { …
Run Code Online (Sandbox Code Playgroud)

pdf android download httpurlconnection fileinputstream

34
推荐指数
3
解决办法
8万
查看次数

使用android intent从服务器打开pdf文件

我正在网上搜索如何在android上使用默认的pdf viewer从服务器打开pdf文件.我找到的是首先下载文件然后在意图中启动它或使用谷歌文档加载它.我不想做所有这些.我只是想从手机的默认pdf查看器直接从服务器加载它.我已经尝试打开视频网址并且有效.但是故意打开pdf网址是行不通的.以下是我的代码;

private void openFilePDF(){
        try{
            Toast.makeText(getBaseContext(), "Opening PDF... ", Toast.LENGTH_SHORT).show();
            Intent inte = new Intent(Intent.ACTION_VIEW);
            inte.setDataAndType(
                    Uri.parse("http://122.248.233.68/pvfiles/Guide-2.pdf"),
                    "application/pdf");

            startActivity(inte);
            }catch(ActivityNotFoundException e){
                Log.e("Viewer not installed on your device.", e.getMessage());
            }
    }
Run Code Online (Sandbox Code Playgroud)

有什么方法可以加载pdf网址吗?

java pdf android android-intent

8
推荐指数
2
解决办法
3万
查看次数