我想把相机里的照片直接上传到一个驱动器文件夹中:
OutputStream outputStream = result.getDriveContents().getOutputStream();
ByteArrayOutputStream bitmapStream = new ByteArrayOutputStream();
/* image is my Bitmap */
image.compress(Bitmap.CompressFormat.PNG, 100, bitmapStream);
try {
outputStream.write(bitmapStream.toByteArray());
} catch (IOException e1) {
Log.i(TAG, "Unable to write file contents.");
}所以我这么做,它就起作用了。问题是,我的照片在驱动器是在非常低的质量,我需要一个高质量的视频。
我已经尝试过这个解决方案了,Converting bitmap to byteArray android
但是在“驱动器”中,照片没有被识别为媒体文件,也无法读取。我可能是失败了。
编辑:我做了与https://stackoverflow.com/a/13000774/6644403完全相同的事情,并通过这种方式在ActivityResult中获取我的位图:
try {
mBitmapToSave = MediaStore.Images.Media.getBitmap(this.getContentResolver(), data.getData());
} catch (IOException e) {
e.printStackTrace();
}发布于 2016-10-17 14:17:24
获取捕获图像的实际图像预定义路径
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
this.startActivityForResult(cameraIntent, 101); 捕获图像后,可以在cameraIntent设置的路径上获取捕获图像。如果不想设置预定义的路径,那么检查意图数据。
if (resultCode == android.app.Activity.RESULT_OK && requestCode == 101) {
try {
path_mm = "Onsuccess_resultcode";
generateNoteOnSD("photo34.txt", path_mm);
Bitmap photo = null;
if (data == null) {
//get Bitmap here.
} else {
Uri u1 = data.getData();
//get uri and find actual path on that uri.
}
}catch(Exception ex) {}
}参考此链接Upload large files to Google Drive using GD API的谷歌驱动器Uploadation。
发布于 2016-10-14 14:02:38
我不是在要求WRITE_EXTERNAL_STORAGE的权利,而是在我的清单中,但是由于api23,我需要明确并询问用户是否还好。
现在好了。
https://stackoverflow.com/questions/39953898
复制相似问题