我正在尝试使用volley plus(https://github.com/DWorkS/VolleyPlus/blob/master/library/src/com/android/volley/request/DownloadRequest.java)下载文件。下面是我的代码:
@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());
}
};
}
文件没有被下载到该位置。这是我的manifest文件:
<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" />
我在安卓棒棒糖上运行我的应用程序。这里的问题是什么?
您试图通过自定义字符串请求下载文件即byte[]。如果你发出字符串请求,你只会得到字符串响应。在您的情况下,您需要发出byte[]请求。
检查下面的链接如何设置自定义请求类的截击。实现自定义射击请求。
下面的链接正在发出与您试图发出的相同的请求。希望能对你有所帮助。使用volley下载文件