DriveApi - 无效的DriveID

时间:2018-02-22 15:09:29

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

我正在使用驱动器并且我遇到了一些问题,我只需要从我的驱动器文件夹中打开一个图像,这就是我在做什么

public Drawable abrirBitmap(String Path) throws IOException {
        d = getResources().getDrawable(R.drawable.amasar);
     /*   if (Path != "nada") {
            Bitmap bitmap = BitmapFactory.decodeFile(Path);
            d = Drawable.createFromPath(Path);
        }*/


        DriveId FileID;
        FileID = DriveId.decodeFromString(Path);
        // [START open_file] Y se lo asignamos al imageView
        Task<DriveContents> openFileTask =
                getDriveResourceClient().openFile(FileID.asDriveFile(), DriveFile.MODE_READ_ONLY);
        // [END open_file]
        // [START read_contents]
        openFileTask
                .continueWithTask(new Continuation<DriveContents, Task<Void>>() {
                    @Override
                    public Task<Void> then(@NonNull Task<DriveContents> task) throws Exception {
                        DriveContents contents = task.getResult();
                        // Process contents...
                        // [START_EXCLUDE]
                        // [START read_as_string]
                        //Leemos la imagen y la traemos a un bitmap
                        InputStream is = contents.getInputStream();
                        Bitmap bitmap = BitmapFactory.decodeStream(is);
                        d = new BitmapDrawable(getResources(),bitmap);

                        // [END read_as_string]
                        // [END_EXCLUDE]
                        // [START discard_contents]
                        Task<Void> discardTask = getDriveResourceClient().discardContents(contents);
                        // [END discard_contents]
                        return discardTask;
                    }
                })
                .addOnFailureListener(new OnFailureListener() {
                    @Override
                    public void onFailure(@NonNull Exception e) {
                        // Handle failure
                        // [START_EXCLUDE]
                        Log.e("TAG", "Unable to read contents", e);
                        // [END_EXCLUDE]
                    }
                });


        return d;
    }

使用此代码我只需打开文件的路径(driveid)并将图像放入其中

在我的oncreate中我只是设置了我的driveID来获取图像

try {
       mImageView.setImageDrawable(abrirBitmap("XXXXXXXXXXXXXXXX="));

    } catch (IOException e) {
        e.printStackTrace();
    }

但我有这个输出

  

无效的DriveID:xxxxxxxxxxxxxxxxxxxxxx =

错误指向我:FileID = DriveId.decodeFromString(Path); 在这里:mImageView.setImageDrawable(abrirBitmap("XXXXXXXXXXXXXXXXX="));

对此有何解决方案?

1 个答案:

答案 0 :(得分:0)

调试代码。将“xxxxxxxxxxxxxxxxxxxxxx”中的任何内容放入变量并记录下来。现在使用获取它 Files.get。如果您无法获取它,则它不存在。