前記事のようにVolley.newRequestQueue(Context)で返されるRequestQueueにはデフォルトで最大5MBのディスクキャッシュが使えるように設定済みですが5MBじゃ足りない、という場合もありますので自前でRequestQueueのインスタンスを作ってみます。
public class VolleyUtil {
/** Default on-disk cache directory. */
private static final String DEFAULT_CACHE_DIR = "volley";
/**
*
* @param context
* @param stack
* @param maxCacheSizeInBytes
* @return
*/
public static RequestQueue createRequestQueue(Context context, HttpStack stack, int maxCacheSizeInBytes) {
File cacheDir = new File(context.getCacheDir(), DEFAULT_CACHE_DIR);
String userAgent = "volley/0";
try {
String packageName = context.getPackageName();
PackageInfo info = context.getPackageManager().getPackageInfo(packageName, 0);
userAgent = packageName + "/" + info.versionCode;
} catch (NameNotFoundException e) {
}
if (stack == null) {
if (Build.VERSION.SDK_INT >= 9) {
stack = new HurlStack();
} else {
// Prior to Gingerbread, HttpUrlConnection was unreliable.
// See: http://android-developers.blogspot.com/2011/09/androids-http-clients.html
stack = new HttpClientStack(AndroidHttpClient.newInstance(userAgent));
}
}
Network network = new BasicNetwork(stack);
RequestQueue queue = new RequestQueue(new DiskBasedCache(cacheDir, maxCacheSizeInBytes), network);
queue.start();
return queue;
}
}
とりあえずこのコードでその場を凌ぎましたがどうも筋が良くないです。。