我想使用排球库下载多个mp3文件。我显然想念一些东西。我的代码如下:
cursor = turistListDbQuery.getAudioCursor("1");
if (cursor.moveToFirst()){
do{
String data = cursor.getString(cursor.getColumnIndex("AUDIO"));
String mUrl="http://android.x25.pl/NowaDroga/audio/"+ data;
request = new DownloadHelper(Request.Method.GET, mUrl, TrackListActivity.this, TrackListActivity.this, null);
MySingleton.getInstance(this).addToRequestQueue(request);
}while(cursor.moveToNext());
}
cursor.close();
我有一个表格,其中保存了要使用提供的mUrl下载的文件的名称。我在每一行上进行迭代,并创建排球请求。 (我从此处获取的DownloadHelper类:how-to-download-video-with-volley 但是如何将参数传递给onResponse方法,这样我就可以使用URI将我的数据库更新为本地存储的下载文件
@Override
public void onResponse(byte[] response) {
HashMap<String, Object> map = new HashMap<String, Object>();
try {
if (response!=null) {
try{
long lenghtOfFile = response.length;
InputStream input = new ByteArrayInputStream(response);
String fiName = request.url;
String fileName = request.getUrl().substring(38);
File file = new File(getApplicationContext().getFilesDir(), fileName );
InsertPositionToList.insertUri(db, file.getAbsolutePath(), fileName );
map.put("resume_path", file.toString());
BufferedOutputStream output = new BufferedOutputStream(new FileOutputStream(file));
byte data[] = new byte[1024];
long total = 0;
while ((count = input.read(data)) != -1) {
total += count;
output.write(data, 0, count);
}
output.flush();
output.close();
input.close();
}catch(IOException e){
e.printStackTrace();
}
}
} catch (Exception e) {
// TODO Auto-generated catch block
Log.d("KEY_ERROR", "UNABLE TO DOWNLOAD FILE");
e.printStackTrace();
}
}
编辑:我目前只能在onResponse方法中获得的唯一URL是用于上一次截击查询