Skip to content Skip to sidebar Skip to footer

How To Get Access To Local File Name In Download Receiver?

I'm trying to get file path of downloaded file, i provided receiver which works but how can i get file name/path? Inside onReceive String action = intent.getAction(); if (DownloadM

Solution 1:

You could get ahold of a DownloadManager instance via the getSystemService() method of Context.

Something like this should work:

@OverridepublicvoidonReceive(Context context, Intent intent) {
    Stringaction= intent.getAction();
    if (DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(action)) {

        // get the DownloadManager instanceDownloadManagermanager= (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);

        DownloadManager.Queryq=newDownloadManager.Query();
        Cursorc= manager.query(q);

        if(c.moveToFirst()) {
            do {
                Stringname= c.getString(c.getColumnIndex(DownloadManager.COLUMN_LOCAL_FILENAME));
                Log.i("DOWNLOAD LISTENER", "file name: " + name);
            } while (c.moveToNext());
        } else {
            Log.i("DOWNLOAD LISTENER", "empty cursor :(");
        }

        c.close();
    }
}

Post a Comment for "How To Get Access To Local File Name In Download Receiver?"