将照片上传到驱动器而不压缩

时间:2016-10-10 08:11:03

标签: android android-bitmap google-drive-android-api drive

我想将相机中的照片直接上传到驱动器文件夹中:

try {
                    mBitmapToSave = MediaStore.Images.Media.getBitmap(this.getContentResolver(), data.getData());
                } catch (IOException e) {
                    e.printStackTrace();
                }

所以我正在做这个并且它正在工作。问题是我在驱动器中的图片质量很差,我需要一个高质量的视频。

我已经尝试过此解决方案Converting bitmap to byteArray android

但是在Drive中,照片无法识别为媒体文件,无法读取。我可能失败了。

编辑:我已完成与https://stackoverflow.com/a/13000774/6644403完全相同的事情并以此方式在ActivityResult中获取我的位图:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.hakobm.location">


<uses-permission android:name="android.permission.INTERNET" />


<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>
</manifest>

2 个答案:

答案 0 :(得分:1)

我没有要求WRITE_EXTERNAL_STORAGE的权利,它在我的清单中但是因为api23我需要明确并询问用户是否正常。

现在很好。

答案 1 :(得分:1)

使用

获取捕获图像的实际图像预定义路径
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
this.startActivityForResult(cameraIntent, 101);  

捕获图像后,您可以在cameraIntent中设置的路径上获取捕获的图像。如果您不想设置预定义路径,请检查Intent数据。

    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以了解Google云端硬盘上传。

相关问题