问题
I am making a notepad app using Google Drive
. Whenever user creates a file in the app, it also creates a file in the Google Drive
. And user can enter the text and save the file, the unsaved text will get committed whenever the internet is available. I am managing the update and create processes within the app using the DriveId
.
If the user wants to use the files with the alternative device using my app, for that I also have the option called DriveId import
. By clicking the option DriveId import
user will be prompted with the input box for entering the existing DriveId
. Using the DriveId
I thought of opening the files, But it was giving an error.
Then I saw an answer given in this SO which clearly says DriveId
can be used only inside the app and device which created the file.
I also found a similar question like mine in here SO But I can’t get my problem solved. I have taken ResourceId using result.getDriveFolder().getDriveId().getResourceId()
How to read the data’s programmatically using the ResourceID? As said in the above answer here I don’t want to change the track and go into Drive REST API
. Is there a way that I can read the data using Google Drive Android API
? I have done all the development process, but in the ending when I try to access from other device it is giving the error. Totally struck.
If I can only read the data using REST API
any simple code will be appreciated. Thanks in advance.
回答1:
Finally Solved the DriveId Issue without REST API.
To get DriveId
on the alternative device. You will need resourceId. You can use following code:-
String resourseId = "xxxxxxxxxxxxx"
Drive.DriveApi.fetchDriveId(mGoogleApiClient,resourseId).setResultCallback(idCallBack);
private ResultCallBack<DriveApi.DriveResult> idCallBack = new ResultCallback<DriveApi.DriveIdResult>() {
@Override
public void onResult(DriveApi.DriveIdResult driveIdResult) {
msg.Log("onResult");
DriveId id = driveIdResult.getDriveId(); //Here you go :)
}
}
来源:https://stackoverflow.com/questions/29149212/cannot-access-google-drive-file