Java Code Examples for android.os.Environment.getDownloadCacheDirectory()

The following are Jave code examples for showing how to use getDownloadCacheDirectory() of the android.os.Environment class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: decoy   File: HttpUtil.java   View Source Code Vote up 6 votes
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");
    }
 
Example 2
Project: unity-obb-downloader   File: Helpers.java   View Source Code Vote up 5 votes
/**
 * @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);
}
 
Example 3
Project: SlotNSlot_Android   File: Helpers.java   View Source Code Vote up 5 votes
/**
 * @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);
}
 
Example 4
Project: Accessibility   File: PathUtils.java   View Source Code Vote up 5 votes
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);
}