本文整理汇总了Java中android.os.Environment.getDownloadCacheDirectory方法的典型用法代码示例。如果您正苦于以下问题:Java Environment.getDownloadCacheDirectory方法的具体用法?Java Environment.getDownloadCacheDirectory怎么用?Java Environment.getDownloadCacheDirectory使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.os.Environment
的用法示例。
在下文中一共展示了Environment.getDownloadCacheDirectory方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: uploadFile
import android.os.Environment; //导入方法依赖的package包/类
public static void uploadFile(String address, Callback callback){
OkHttpClient client = new OkHttpClient();
File file = new File(Environment.getDownloadCacheDirectory(),"test.jpg");
Log.d("upload",file.toString());
RequestBody fileBody = RequestBody.create(MediaType.parse("application/octet-stream"),file);
Log.d("upload","1");
// ------WebKitFormBoundaryJ0iuGTPmhsoF94SF
// Content-Disposition: form-data; name="file"; filename="timg.jpg"
// Content-Type: image/jpeg
//
// ------WebKitFormBoundaryJ0iuGTPmhsoF94SF
// Content-Disposition: form-data; name="submit"
RequestBody requestBody = new MultipartBody.Builder().setType(MultipartBody.FORM)
// .addPart(Headers.of("Content-Disposition","form-data; name=\"username\""),RequestBody.create(null,"孙启鹏"))
.addPart(Headers.of("Content-Type","image/jpeg"),fileBody)
.addPart(Headers.of("Content-Disposition","form-data; name=\"submit\""),RequestBody.create(null,"孙启鹏"))
.build();
Log.d("upload","2");
Request request = new Request.Builder().url(address).post(requestBody).build();
Log.d("upload","3");
client.newCall(request).enqueue(callback);
Log.d("upload","4");
}
示例2: getFilesystemRoot
import android.os.Environment; //导入方法依赖的package包/类
/**
* @return the root of the filesystem containing the given path
*/
public static File getFilesystemRoot(String path) {
File cache = Environment.getDownloadCacheDirectory();
if (path.startsWith(cache.getPath())) {
return cache;
}
File external = Environment.getExternalStorageDirectory();
if (path.startsWith(external.getPath())) {
return external;
}
throw new IllegalArgumentException(
"Cannot determine filesystem root for " + path);
}
示例3: getFilesystemRoot
import android.os.Environment; //导入方法依赖的package包/类
public static File getFilesystemRoot(String path) {
File cache = Environment.getDownloadCacheDirectory();
if (path.startsWith(cache.getPath())) {
return cache;
}
File external = Environment.getExternalStorageDirectory();
if (path.startsWith(external.getPath())) {
return external;
}
throw new IllegalArgumentException(
"Cannot determine filesystem root for " + path);
}