想在适当的Andr​​oid应用程序中打开下载文件 [英] Want to open downloaded file in appropriate application in Android

查看:158
本文介绍了想在适当的Andr​​oid应用程序中打开下载文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须从我的服务器下载文件,我的应用程序,并保存到一个私有文件夹。

I have to download a document from my server, to my app and save into a private folder.

该文件可以像 .DOC,.PDF,.docs什么,.JPG 等。

现在,我想的是,下载完成后,我表现出警报对话框来打开文档。

Now, what I want is, after the download is completed, I show an Alert Dialog to open the document.

当我点击笔按钮然后打开特定文件在适当的应用程序,如果应用程序不可用,则显示对话框下载应用程序。

When I click on the pen button then open that particular file in an appropriate application and if the app is not available, then show Dialog to download app.

给我一些这方面的提示。

Give me some hint on this.

先谢谢了。

推荐答案

试试这个方法:

邮件附件打开

        File file = new File(yourdownloadfilePATH);

        if ((download_file_name.endsWith(".pdf")) || (download_file_name.endsWith(".PDF"))){            

            if(file.exists() && file.length()!=0){

            Intent intent = new Intent();

            intent.setClassName("com.adobe.reader","com.adobe.reader.AdobeReader");

            intent.setAction(android.content.Intent.ACTION_VIEW);

            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

            Uri uri = Uri.fromFile(file);

            intent.setDataAndType(uri, "application/pdf");

            try {

                startActivity(intent);

            } catch (Exception e) {

                                AlertDialog.Builder builder = new AlertDialog.Builder(youractivity.this);
                                builder.setTitle("No Application Found");
                                    builder.setMessage("Download application from Android Market?");
                                    builder.setPositiveButton(
                                            "Yes, Please",
                                            new DialogInterface.OnClickListener() {
                                                @Override
                                                public void onClick(
                                                        DialogInterface dialog,
                                                        int which) {
                                                    Intent marketIntent = new Intent(
                                                            Intent.ACTION_VIEW);
                                                    marketIntent.setData(Uri
                                                            .parse("market://details?id=com.adobe.reader"));
                                                    startActivity(marketIntent);
                                                }
                                            });
                                    builder.setNegativeButton("No, Thanks",
                                            null);
                                    builder.create().show();
            }

    }
 }  else if ((download_file_name.endsWith(".jpg"))||  (download_file_name.endsWith(".bmp"))||
(download_file_name.endsWith(".BMP"))||(download_file_name.endsWith(".png"))||  (download_file_name.endsWith(".PNG"))||(download_file_name.endsWith(".gif"))||   (download_file_name.endsWith(".GIF"))||
                            (download_file_name.endsWith(".JPG"))) {

        Intent intent = new Intent();
        intent.setAction(android.content.Intent.ACTION_VIEW);
        intent.setDataAndType(Uri.fromFile(file), "image/*");       
        startActivity(intent);

    }
else if ((download_file_name.endsWith(".txt"))) {


    Intent intent = new Intent();
    intent.setAction(android.content.Intent.ACTION_VIEW);
    intent.setDataAndType(Uri.fromFile(file), "text/html");
    startActivity(intent);

}

这篇关于想在适当的Andr​​oid应用程序中打开下载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆