0

我是android开发的新手。

我为自动下载器构建应用程序,

每次下载都可以正常工作并保存在我的 SD 卡上,但设备上没有打开 drm 文件。

我解释一下,我尝试下载扩展名为 dd\dm 的文件,如果常规浏览器下载 dd\dm 文件,设备会将它们解压缩为 dcf 扩展名。

我的应用程序没有这样做...我注意到如果我的设备重新启动,一切都是正确的,实际上设备将此文件的扩展名更改为 dcf,我可以播放这首歌,如果我没有发起者重新启动到设备,文件扩展名保留在 .dd.dm

mt 内容类型为:application/vnd.oma.drm.message

有人知道我需要怎么照顾吗??

这是我的代码......

class DownloadFileFromURL extends AsyncTask<String, String, String> {

    /**
     * Before starting background thread
     * Show Progress Bar Dialog
     * */
    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        showDialog(progress_bar_type);
    }

    /**
     * Downloading file in background thread
     * */
    @Override
    protected String doInBackground(String... f_url) {
        int count;
        try {

            URL url = new URL(f_url[0]);
            URLConnection conection = url.openConnection();
            conection.getContent();
            conection.connect();
            // getting file length
            int lenghtOfFile = conection.getContentLength();

            // Insert Information Of File to Array
            getCurrentArray()[index].setSizeOfFile(OrangeFile.convertToStringRepresentation(lenghtOfFile));
            getCurrentArray()[index].setMimeOfFile(conection.getContentType());

            // input stream to read file - with 8k buffer
            InputStream input = new BufferedInputStream(url.openStream(), 8192);

            // Output stream to write file
            OutputStream output = new FileOutputStream(mPath + getCurrentArray()[index].getNameOfFile() + "." + getCurrentArray()[index].getExtOfFile());


            byte data[] = new byte[1024];

            long total = 0;

            while ((count = input.read(data)) != -1) {
                total += count;
                // publishing the progress....
                // After this onProgressUpdate will be called
                publishProgress(""+(int)((total*100)/lenghtOfFile));

                // writing data to file
                output.write(data, 0, count);
            }

            // flushing output
            output.flush();

            // closing streams
            output.close();
            input.close();


        } catch (Exception e) {
            Log.e("Error: ", e.getMessage());
        }

        return null;
    }
4

1 回答 1

0

虽然这是一个老问题,但不确定您是否已经得到任何答案。下面是如何克服这个问题。

首先,您无法通过文件连接 API 下载“.dm”和“.dd”文件,尽管您可以成功下载它们,但不能直接使用它。

检查此http://www.developer.nokia.com/Community/Wiki/Saving_and_reading_DRM-protected_files_using_FileConnection_API_and_Mobile_Media_API

当您的设备操作系统对 sd 卡进行彻底的内存扫描时,“.dm”文件会自动转换为“.dcf”。如果您只是卸载 sd 卡并重新安装,那么文件也会被转换而无需重新启动设备。

那么如何实际下载这些文件以立即使用而无需重新启动设备。

如上述链接所述,您只能通过 HTTP(在浏览器中)或 MMS 下载受保护的内容。

因此,使用指向服务器上“.dm”文件的 url 创建一个 Intent 并触发它。下载完成后,浏览器将捕获 url 并下载文件并自动将其转换为“.dcf”。

希望这可以帮助。

编辑:通过文件连接 API 下载文件后,您可以通过使用“ ACTION_MEDIA_SCANNER_SCAN_FILE ”操作创建意图并发送广播来显式调用媒体扫描器。

于 2013-07-05T06:42:47.233 回答