繁体   English   中英

DriveApi - 无效的 DriveID

[英]DriveApi - Invalid DriveID

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

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();
    }

但我有这个输出

驱动器 ID 无效:xxxxxxxxxxxxxxxxxxxxxxxx=

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

有什么解决办法吗?

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM