Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google drive android API演示无法正常工作_Android - Fatal编程技术网

Google drive android API演示无法正常工作

Google drive android API演示无法正常工作,android,Android,我对这个问题已经有很长一段时间了。我想把我的sqlite数据库上传到谷歌硬盘,然后再下载。问题是,我发现的驱动器演示不起作用。我需要获取DriveId,但我不知道如何获取,因为示例应用程序无法工作。我想在文件夹中创建一个文件。如果有任何工作教程,或一步一步,我可以使用它将不胜感激。我真的需要一些人帮我把这件事做好 我只是想澄清一下,这就是我想要的: 有人能告诉我如何获取DriveId,以便让演示应用程序正常工作吗?如果这是不可能的,是否有任何一步一步的教程可以帮助我实现上传/下载文件夹中的文件?

我对这个问题已经有很长一段时间了。我想把我的sqlite数据库上传到谷歌硬盘,然后再下载。问题是,我发现的驱动器演示不起作用。我需要获取DriveId,但我不知道如何获取,因为示例应用程序无法工作。我想
在文件夹中创建一个文件
。如果有任何工作教程,或一步一步,我可以使用它将不胜感激。我真的需要一些人帮我把这件事做好

我只是想澄清一下,这就是我想要的:

有人能告诉我如何获取DriveId,以便让演示应用程序正常工作吗?如果这是不可能的,是否有任何一步一步的教程可以帮助我实现上传/下载文件夹中的文件?如果你需要什么,请告诉我

这是
CreateFileInFolderActivity.class

public class CreateFileInFolderActivity extends BaseDemoActivity {

    private DriveId mFolderDriveId;

    @Override
    public void onConnected(Bundle connectionHint) {
        super.onConnected(connectionHint);
        Drive.DriveApi.fetchDriveId(getGoogleApiClient(), EXISTING_FOLDER_ID)
                .setResultCallback(idCallback);
    }

    final private ResultCallback<DriveIdResult> idCallback = new ResultCallback<DriveIdResult>() {
        @Override
        public void onResult(DriveIdResult result) {
            if (!result.getStatus().isSuccess()) {
                showMessage("Cannot find DriveId. Are you authorized to view this file?");
                return;
            }
            mFolderDriveId = result.getDriveId();
            Drive.DriveApi.newContents(getGoogleApiClient())
                    .setResultCallback(contentsResult);
        }
    };

    final private ResultCallback<ContentsResult> contentsResult = new
            ResultCallback<ContentsResult>() {
        @Override
        public void onResult(ContentsResult result) {
            if (!result.getStatus().isSuccess()) {
                showMessage("Error while trying to create new file contents");
                return;
            }
            DriveFolder folder = Drive.DriveApi.getFolder(getGoogleApiClient(), mFolderDriveId);
            MetadataChangeSet changeSet = new MetadataChangeSet.Builder()
                    .setTitle("New file")
                    .setMimeType("text/plain")
                    .setStarred(true).build();
            folder.createFile(getGoogleApiClient(), changeSet, result.getContents())
                    .setResultCallback(fileCallback);
        }
    };

    final private ResultCallback<DriveFileResult> fileCallback = new
            ResultCallback<DriveFileResult>() {
        @Override
        public void onResult(DriveFileResult result) {
            if (!result.getStatus().isSuccess()) {
                showMessage("Error while trying to create the file");
                return;
            }
            showMessage("Created a file: " + result.getDriveFile().getDriveId());
        }
    };
}
package com.google.android.gms.drive.sample.demo;

import android.app.Activity;
import android.content.Intent;
import android.content.IntentSender.SendIntentException;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;

import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.drive.Drive;

/**
* An abstract activity that handles authorization and connection to the Drive
* services.
*/
public abstract class BaseDemoActivity extends Activity implements
        GoogleApiClient.ConnectionCallbacks,
        GoogleApiClient.OnConnectionFailedListener {

    private static final String TAG = "BaseDriveActivity";

    /**
     * DriveId of an existing folder to be used as a parent folder in
     * folder operations samples.
     * Existing folder ID = CAESHDBCN2RKT1FUNnYzMWlkWE5VUzJKcVNuWXdVRGcYNiCGvM3xolE= and it
     * does not work
     */
    public static final String EXISTING_FOLDER_ID = "jqatpab1jsujpum14p7cq41pbtiij32q";

    /**
     * DriveId of an existing file to be used in file operation samples..
     */
    public static final String EXISTING_FILE_ID = "0ByfSjdPVs9MZTHBmMVdSeWxaNTg";

    /**
     * Extra for account name.
     */
    protected static final String EXTRA_ACCOUNT_NAME = "account_name";

   /**
     * Request code for auto Google Play Services error resolution.
     */
    protected static final int REQUEST_CODE_RESOLUTION = 1;

    /**
     * Next available request code.
     */
    protected static final int NEXT_AVAILABLE_REQUEST_CODE = 2;

    /**
     * Google API client.
     */
    private GoogleApiClient mGoogleApiClient;

    /**
     * Called when activity gets visible. A connection to Drive services need to
     * be initiated as soon as the activity is visible. Registers
     * {@code ConnectionCallbacks} and {@code OnConnectionFailedListener} on the
     * activities itself.
     */
    @Override
    protected void onResume() {
        super.onResume();
        if (mGoogleApiClient == null) {
            mGoogleApiClient = new GoogleApiClient.Builder(this)
                    .addApi(Drive.API)
                    .addScope(Drive.SCOPE_FILE)
                    .addScope(Drive.SCOPE_APPFOLDER) // required for App Folder sample
                    .addConnectionCallbacks(this)
                    .addOnConnectionFailedListener(this)
                    .build();
        }
        mGoogleApiClient.connect();
    }

    /**
     * Handles resolution callbacks.
     */
    @Override
    protected void onActivityResult(int requestCode, int resultCode,
            Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == REQUEST_CODE_RESOLUTION && resultCode == RESULT_OK) {
            mGoogleApiClient.connect();
        }
    }

    /**
     * Called when activity gets invisible. Connection to Drive service needs to
     * be disconnected as soon as an activity is invisible.
     */
    @Override
    protected void onPause() {
        if (mGoogleApiClient != null) {
            mGoogleApiClient.disconnect();
        }
        super.onPause();
    }

    /**
     * Called when {@code mGoogleApiClient} is connected.
     */
    @Override
    public void onConnected(Bundle connectionHint) {
        Log.i(TAG, "GoogleApiClient connected");
    }

    /**
     * Called when {@code mGoogleApiClient} is disconnected.
     */
    @Override
    public void onConnectionSuspended(int cause) {
        Log.i(TAG, "GoogleApiClient connection suspended");
    }

    /**
     * Called when {@code mGoogleApiClient} is trying to connect but failed.
     * Handle {@code result.getResolution()} if there is a resolution is
     * available.
     */
    @Override
    public void onConnectionFailed(ConnectionResult result) {
        Log.i(TAG, "GoogleApiClient connection failed: " + result.toString());
        if (!result.hasResolution()) {
            // show the localized error dialog.
            GooglePlayServicesUtil.getErrorDialog(result.getErrorCode(), this, 0).show();
            return;
        }
        try {
            result.startResolutionForResult(this, REQUEST_CODE_RESOLUTION);
        } catch (SendIntentException e) {
            Log.e(TAG, "Exception while starting resolution activity", e);
        }
    }

    /**
     * Shows a toast message.
     */
    public void showMessage(String message) {
        Toast.makeText(this, message, Toast.LENGTH_LONG).show();
    }

    /**
     * Getter for the {@code GoogleApiClient}.
     */
    public GoogleApiClient getGoogleApiClient() {
      return mGoogleApiClient;
    }
}

提前谢谢。

我不确定如何让演示应用程序正常工作,但您可以尝试在应用程序中创建自己的文件夹,并使用其中的驱动器ID在其中创建文件

在这些示例中,有一个示例活动用于创建名为CreateFolderActivity的文件夹。在结果回调中,它返回一个DriveFolderResult,您可以使用它来查询DriveID

result.getDriveFolder.getDriveId();

然后在创建文件时使用该驱动器ID。

请查看ListFilesInFolderActivity类,并查看resultAdapter内部,从中可以从元数据检索驱动器ID。然后是RetrieveContentsWithProgressDialogActivity,您可以在其中检索驱动器id以访问文件。

您从哪里获得现有的\u文件夹\u id和现有的\u文件\u id。我只有OAuth 2.0配置中的客户端id…我的内存可能有点生锈,但我想您在google drive api上注册应用程序时会得到这些@powder366I是否有一个链接,您可以在其中注册驱动器SDK,到目前为止,我只注册了我的OAuth…您必须在注册您的应用程序,一旦您登录@powder366I,就会有一个创建项目按钮,然后是API和AUTH,然后是凭据:OAuth,创建新的客户端ID