本文整理匯總了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);
}