将诸如图像,视频,文档之类的文件上传到我的驱动器文件夹中

问题描述

基本上,我正在创建一个应用程序,用户可以通过创建文件夹在驱动器上上传他/她的文件在这里,我已经成功创建了一个文件夹,现在面临的问题是如何在用户刚刚创建的文件夹上上传文件用户可以在其中选择多个图像,视频,文档等。出于选择目的,我有选择的意图,但无法获取如何上传它。这是我到目前为止所做的代码

对于创建文件夹,我现在使用此方法,我要在此文件夹中上传文件,请告诉我

if (mDriveServiceHelper == null) {
                    return;
                }
                mDriveServiceHelper.createFolder("FolderNew",null)
                        .addOnSuccessListener(new OnSuccessListener<GoogleDriveFileHolder>() {
                            @Override
                            public void onSuccess(GoogleDriveFileHolder googleDriveFileHolder) {
                                Gson gson = new Gson();
                                Log.d(TAG,"onSuccess: " + gson.toJson(googleDriveFileHolder));
                            }
                        })
                        .addOnFailureListener(new OnFailureListener() {
                            @Override
                            public void onFailure(@NonNull Exception e) {
                                Log.d(TAG,"onFailure: " + e.getMessage());

                            }
                        });

用于拾取图像和视频

    Intent intent = new Intent();
        intent.setType("image/*");
        intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE,true);
        intent.setAction(Intent.ACTION_GET_CONTENT);
        startActivityForResult(Intent.createChooser(intent,"Select Picture"),PICK_IMAGE_MULTIPLE);

@Override
    protected void onActivityResult(int requestCode,int resultCode,Intent data) {
        try {
            // When an Image is picked
            if (requestCode == PICK_IMAGE_MULTIPLE && resultCode == RESULT_OK
                    && null != data) {
                // Get the Image from data

                String[] filePathColumn = { MediaStore.Images.Media.DATA };
                imagesEncodedList = new ArrayList<String>();
                if(data.getData()!=null){

                    Uri mImageUri=data.getData();

                    // Get the cursor
                    Cursor cursor = getContentResolver().query(mImageUri,filePathColumn,null,null);
                    // Move to first row
                    cursor.movetoFirst();

                    int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
                    imageEncoded  = cursor.getString(columnIndex);
                    cursor.close();

                } else {
                    if (data.getClipData() != null) {
                        ClipData mClipData = data.getClipData();
                        ArrayList<Uri> mArrayUri = new ArrayList<Uri>();
                        for (int i = 0; i < mClipData.getItemCount(); i++) {

                            ClipData.Item item = mClipData.getItemAt(i);
                            Uri uri = item.getUri();
                            mArrayUri.add(uri);
                            // Get the cursor
                            Cursor cursor = getContentResolver().query(uri,null);
                            // Move to first row
                            cursor.movetoFirst();

                            int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
                            imageEncoded  = cursor.getString(columnIndex);
                            imagesEncodedList.add(imageEncoded);
                            Toast.makeText(this,""+uri,Toast.LENGTH_SHORT).show();
                            Toast.makeText(this,""+imageEncoded,""+imagesEncodedList,Toast.LENGTH_SHORT).show();
                            cursor.close();

                        }
                        Log.v("LOG_TAG","Selected Images" + mArrayUri.size());
                    }
                }
            } else {
                Toast.makeText(this,"You haven't picked Image",Toast.LENGTH_LONG).show();
            }
        } catch (Exception e) {
            Toast.makeText(this,"Something went wrong",Toast.LENGTH_LONG)
                    .show();
        }

        super.onActivityResult(requestCode,resultCode,data);

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)