1
我有功能,工作正常!但它通過Drive ID?如果Drive id被刪除或破壞,該怎麼辦?如何從App文件夾中讀取文件沒有DriveId的谷歌驅動器?
是他們找到驅動器ID的方法嗎?
我面臨的困難在這樣的場景中
- 用戶重新加入我的應用程序或更改設備
- 如果我錯過了我的驅動器ID從共享偏好
======= ================================================ 我的working functon
readFromGooDrive(DriveId mDriveId) {
byte[] buf = null;
if (getGoogleApiClient() != null && getGoogleApiClient().isConnected()) try {
DriveFile df = Drive.DriveApi.getFile(getGoogleApiClient(), mDriveId);
df.open(getGoogleApiClient(), DriveFile.MODE_READ_ONLY, null)
.setResultCallback(new ResultCallback<DriveContentsResult>() {
@Override
public void onResult(DriveContentsResult driveContentsResult) {
if ((driveContentsResult != null) && driveContentsResult.getStatus().isSuccess()) {
DriveContents contents = driveContentsResult.getDriveContents();
BufferedInputStream bis = new BufferedInputStream(contents.getInputStream());
byte[] buffer = new byte[1024];
int bytesread = 0;
FileOutputStream outStream;
try
{
String databasePath = getBaseContext().getDatabasePath("my database").getPath();
outStream = new FileOutputStream(databasePath);
while((bytesread = bis.read(buffer)) != -1)
{
outStream.write(buffer,0,bytesread);
}
outStream.flush();
bis.close();
outStream.close();
}
catch (FileNotFoundException e)
{
Log.i(TAG,e.getMessage());
}
catch (IOException e)
{
Log.i(TAG,e.getMessage());
}
finally {
Toast.makeText(getBaseContext(),"Data from Google Drive restored successfully." , Toast.LENGTH_LONG).show();
}
contents.discard(getGoogleApiClient());
}
}
});
} catch (Exception e) { e.printStackTrace(); }
}
閱讀此鏈接:https://developers.google.com/drive/android/auth 我認爲沒有必要使用驅動器Id – dipali
你能請舉出一個'DriveId'將被刪除的實例? – Teyam
我正在將一個mydb文件上傳到應用程序文件夾中的驅動器。現在我卸載應用程序,然後再次安裝,並試圖檢索應用程序文件夾的內容,但我沒有得到沒有DriveId? – Harish