【发布时间】:2016-09-26 05:44:31
【问题描述】:
我的功能和工作正常!但它的绕过驱动器ID?如果 Drive id 被删除或销毁怎么办!
他们有什么方法可以找到驱动器ID吗?
我在这种情况下遇到了困难
- 用户重新加入我的应用或更换设备
- 如果我错过了共享偏好设置中的驱动器 ID
================================================ ======== 我的工作功能
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(); }
}
【问题讨论】:
-
阅读此链接:developers.google.com/drive/android/auth 我认为不需要使用 driveID
-
您能否举一个例子,其中
DriveId将被删除? -
我正在将一个 mydb 文件上传到 app 文件夹中的驱动器中。现在我卸载应用程序然后再次安装,并尝试检索应用程序文件夹内容,但我没有 DriveId?
标签: android google-drive-android-api drive