Получение result.getDriveFolder (). GetDriveId (). GetResourceId () всегда пусто

Попытка поместить все файлы в папку, но получение result.getDriveFolder (). GetDriveId (). GetResourceId () всегда равно нулю. я искал и нашел несколько ссылок, и я попытался выполнить шаги, упомянутые в этой ссылкевведите описание ссылки здесь

Вот мой код: -

  public class MainActivity extends Activity implements ConnectionCallbacks,
        OnConnectionFailedListener {
    public ArrayList songsList = new ArrayList();
    private static final String TAG = "drive-quickstart";
    private GoogleApiClient mGoogleApiClient;
    public static ArrayList<File> listAllMusicFiles = new ArrayList<File>();
    protected static final int REQUEST_CODE_RESOLUTION = 1;
    protected static final int NEXT_AVAILABLE_REQUEST_CODE = 2;
    private DriveId mFolderDriveId;
    public static final String EXISTING_FOLDER_ID = "0B2EEtIjPUdX6MERsWlYxN3J6RU0";
    public static final String EXISTING_FILE_ID = "0ByfSjdPVs9MZTHBmMVdSeWxaNTg";

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

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        final File mainDir = new File(Environment.getExternalStorageDirectory()
                .getPath());
        loadSdcardfiles(mainDir);
    }

    /**
     * Create a new file and save it to Drive.
     */

    private void saveFileToDrive(final File file) {
        Log.i(TAG, "Creating new contents.");
        Drive.DriveApi.newDriveContents(mGoogleApiClient).setResultCallback(
                new ResultCallback<DriveApi.DriveContentsResult>() {

                    @Override
                    public void onResult(DriveApi.DriveContentsResult result) {
                        if (!result.getStatus().isSuccess()) {
                            Log.i(TAG, "Failed to create new contents.");
                            return;
                        }

                        final DriveContents driveContents = result
                                .getDriveContents();
                        Log.i(TAG, "New contents created.");
                        OutputStream outputStream = result.getDriveContents()
                                .getOutputStream();
                        try {
                            @SuppressWarnings("resource")
                            FileInputStream fileInputStream = new FileInputStream(
                                    file);
                            byte[] buffer = new byte[1024];
                            int bytesRead;
                            while ((bytesRead = fileInputStream.read(buffer)) != -1) {
                                outputStream.write(buffer, 0, bytesRead);
                            }
                        } catch (IOException e1) {
                            Log.i(TAG, "Unable to write file contents.");
                        }
                        DriveFolder folder = mFolderDriveId.asDriveFolder();

                        MetadataChangeSet metadataChangeSet = new MetadataChangeSet.Builder()
                                .setTitle(file.getName()).setStarred(true)
                                .build();

                        // create a file on root folder

                        folder.createFile(mGoogleApiClient, metadataChangeSet,
                                driveContents).setResultCallback(fileCallback);

                        // Drive.DriveApi
                        // .getRootFolder(mGoogleApiClient)
                        // .createFile(mGoogleApiClient,
                        // metadataChangeSet, driveContents)
                        // .setResultCallback(fileCallback);

                        try {
                        } catch (Exception e) {
                        }
                    }
                });
    }

    private void loadSdcardfiles(File aFile) {
        if (aFile.isFile()) {
            if (aFile.getAbsolutePath().endsWith(".mp3")) {
                listAllMusicFiles.add(aFile);
            }
        } else if (aFile.isDirectory()) {
            File[] listOfFiles = aFile.listFiles();
            if (listOfFiles != null) {
                for (int i = 0; i < listOfFiles.length; i++) {
                    if (listOfFiles[i].isFile()) {
                        loadSdcardfiles(listOfFiles[i]);
                    }

                }
            } else {
            }
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
        if (mGoogleApiClient == null) {
            mGoogleApiClient = new GoogleApiClient.Builder(this)
                    .addApi(Drive.API).addScope(Drive.SCOPE_FILE)
                    .addConnectionCallbacks(this)
                    .addOnConnectionFailedListener(this).build();
        }
        mGoogleApiClient.connect();
    }

    @Override
    protected void onPause() {
        if (mGoogleApiClient != null) {
            mGoogleApiClient.disconnect();
        }
        super.onPause();
    }

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

    public void showMessage(String message) {
        Toast.makeText(this, message, Toast.LENGTH_LONG).show();
    }

    @Override
    public void onConnectionFailed(ConnectionResult result) {
        Log.i(TAG, "GoogleApiClient connection failed: " + result.toString());
        if (!result.hasResolution()) {
            GoogleApiAvailability.getInstance()
                    .getErrorDialog(this, result.getErrorCode(), 0).show();
            return;
        }
        try {
            result.startResolutionForResult(this, REQUEST_CODE_RESOLUTION);
        } catch (SendIntentException e) {
            Log.e(TAG, "Exception while starting resolution activity", e);
        }
    }

    @Override
    public void onConnected(Bundle connectionHint) {
        Toast.makeText(this, "API client connected" + listAllMusicFiles.get(0),
                1000).show();
        if (listAllMusicFiles.size() == 0) {
            return;
        } else {
            MetadataChangeSet changeSet = new MetadataChangeSet.Builder()
                    .setTitle("Siddharth").build();

            Drive.DriveApi.getRootFolder(mGoogleApiClient)
                    .createFolder(mGoogleApiClient, changeSet)
                    .setResultCallback(callback);

        }

    }

    @Override
    public void onConnectionSuspended(int cause) {
        Toast.makeText(this, "GoogleApiClient connection suspended", 1000)
                .show();
    }

    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();
            for (int i = 0; i < listAllMusicFiles.size(); i++) {
                saveFileToDrive(listAllMusicFiles.get(i));
            }

        }
    };
    final ResultCallback<DriveFolderResult> callback = new ResultCallback<DriveFolderResult>() {
        @Override
        public void onResult(final DriveFolderResult result) {
            if (!result.getStatus().isSuccess()) {
                showMessage("Error while trying to create the folder");
                return;
            }
            showMessage("Created a folder: "
                    + result.getDriveFolder().getDriveId());
            mFolderDriveId = result.getDriveFolder().getDriveId();
            DriveFolder folder = Drive.DriveApi.getFolder(mGoogleApiClient,
                    result.getDriveFolder().getDriveId());
            folder.addChangeSubscription(mGoogleApiClient);
,
        }
    };

    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 with content: "
                    + result.getDriveFile().getDriveId());

        }
    };

    public class MyDriveEventService extends DriveEventService {

        @Override
        public void onChange(ChangeEvent event) {
            Log.d(TAG, event.toString());
            Drive.DriveApi.fetchDriveId(mGoogleApiClient,
                    mFolderDriveId.getResourceId()).setResultCallback(
                    idCallback);
        }

    }
}

Может ли кто-нибудь предложить мне, как это сделать, заранее спасибо

Ответы на вопрос(1)

Ваш ответ на вопрос