0

I'm newbe in android development.

I bulid app for automatic downloader,

every downloads work properly and save on my sd card, but the drm file not open on device.

I explain my self, I try download file with extension dd\dm, If the regular browser download dd\dm files, the device extract them to dcf extension.

my app not do that... I notied then if my device do restart, every is right, in fact the device change the extension of this file to dcf, and i can play this song, If i didnt originator restart to device, the files extension stay on .dd.dm

mt content type is: application/vnd.oma.drm.message

Somebody knows how i need care of that??

This Is my code.....

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;
    }
user1659684
  • 1
  • 1
  • 3

1 Answers1

0

Though its an old question, not sure if you got any answer for this already. Below is how to overcome this problem.

First of all you cannot download ".dm" & ".dd" files via File Connection API, though you can successfully download them you cannot use it directly.

Check this http://www.developer.nokia.com/Community/Wiki/Saving_and_reading_DRM-protected_files_using_FileConnection_API_and_Mobile_Media_API

".dm" files are converted to ".dcf" automatically when there is a thorough memory scan of sd card by your device OS. If you just unmount the sd card and remount then also the files are converted without having to restart the device.

So how to actually download these files to be used immediately without restarting the device.

As stated in the above link you can download the protected content only via HTTP (in browser) or MMS.

So create an Intent with url pointing to the ".dm" file on your server and fire it. Browser will catch the url and download the file and convert it to ".dcf" automatically as soon as the download is complete.

Hope this helps.

Edit: You can explicitly invoke the media scanner once you downloaded the file via File Connection API by creating an intent with action "ACTION_MEDIA_SCANNER_SCAN_FILE" and send a broadcast.

Sudhaker
  • 785
  • 1
  • 6
  • 13