0

I am trying to download a file using volley plus(https://github.com/DWorkS/VolleyPlus/blob/master/library/src/com/android/volley/request/DownloadRequest.java) . Here's my code:

@Override
public void downloadFile(String url, final String path, OnViewDocsFinished mListener) {
    //url = "http://www.orimi.com/pdf-test.pdf"
    //String name = "passport.pdf";
    //String path = Environment.DIRECTORY_DOWNLOADS+"/"+name;
    DownloadRequest request = new DownloadRequest(url, path,
            createSuccessListener(mListener, path),
            createErrorListener(mListener));
    VolleySingleton.getRequestQueue().add(request);
}
private Response.Listener<String> createSuccessListener(final OnViewDocsFinished loginListener, final String path) {
    return new Response.Listener<String>() {
        @Override
        public void onResponse(String response) {
            try {
                Log.i(TAG, response.toString());
                loginListener.onDownloadFinished(path);
            } catch (Exception e) {

            }
        }
    };
}
private Response.ErrorListener createErrorListener(final OnViewDocsFinished loginListener) {
    return new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            Log.e(TAG, error.toString());

        }
    };
}

The file is not getting downloaded to the location. Here's my manifest file:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="in.yumigo.yumigovendor">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.ACCESS_DOWNLOAD_MANAGER" />
<uses-permission android:name="android.permission.DOWNLOAD_WITHOUT_NOTIFICATION" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

I am running my app on Android Lollipop. WHat's the issue here guys?

androider
  • 982
  • 6
  • 16
  • 32

1 Answers1

0

You trying to download file i.e.byte[] by making custom string request. If you make string request you will get only string response. In your case you need to make byte[] request.

Check below link how to setup custom request class for volley. Implementing a Custom Volley Request.

This below link is making the same request what you are trying to make. Hope it may help you. Downloading files using volley.

Anand
  • 857
  • 1
  • 12
  • 18
  • As a caveat, please note that Volley holds all the data in memory; for file downloads, its better to write small chunks to the storage rather than holding everything in memory. – user90766 Jan 06 '17 at 04:34