android:如何从Android应用程序中的驱动器的app文件夹中检索文件内容

时间:2015-06-09 11:27:29

标签: android

我正在将文件上传到app文件夹中的驱动器中。现在我卸载应用程序然后再次安装,并尝试检索应用程序文件夹内容,但我没有得到任何文件内容和logcat显示GoogleApiDrive连接失败,但然后再次按下按钮检索内容,我得到的数据。请问,任何人都可以帮我解决卸载应用程序后第一次检索数据的问题,但是我可以检索数据吗?

@Override
    public void onConnected(Bundle connectionHint) {
        super.onConnected(connectionHint);

        //query for file name in drive
        query = new Query.Builder()
        .addFilter(Filters.eq(SearchableField.MIME_TYPE, "text/plain"))
        .addFilter(
                Filters.eq(SearchableField.TITLE, "appfolderdata"))
                .build();
        Drive.DriveApi.query(getGoogleApiClient(), query).setResultCallback(
                metadataCallback);

    }

    final private ResultCallback<MetadataBufferResult> metadataCallback = new ResultCallback<MetadataBufferResult>() {

        DriveId driveId;
        @Override
        public void onResult(MetadataBufferResult result) {
            if (!result.getStatus().isSuccess()) {
                showMessage("Problem while retrieving results");
                finish();
            }
            //get metadata if backup file is present in drive
            MetadataBuffer metadata = result.getMetadataBuffer();
            System.out.println();
            if (metadata.getCount() > 0) {
                System.out.println("metadata.getCount() is : " + metadata.getCount());
                driveId = metadata.get(0).getDriveId();
                System.out.println("meta data drive id is : " + driveId);
            }
            metadata.close();
            if(driveId != null){
                Drive.DriveApi.fetchDriveId(getGoogleApiClient(), driveId.getResourceId())
                .setResultCallback(idCallback);
            }else{
                if(count < 3){
                    Drive.DriveApi.query(getGoogleApiClient(), query).setResultCallback(
                            metadataCallback);
                    count++;
                }else{
                    showMessage("Problem while retrieving results");
                    if(dialog != null){
                        dialog.dismiss();
                    }
                    finish();
                }
            }
        }
    };

0 个答案:

没有答案