本文整理汇总了Java中com.google.android.gms.drive.DriveApi.DriveContentsResult类的典型用法代码示例。如果您正苦于以下问题:Java DriveContentsResult类的具体用法?Java DriveContentsResult怎么用?Java DriveContentsResult使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DriveContentsResult类属于com.google.android.gms.drive.DriveApi包,在下文中一共展示了DriveContentsResult类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: onResult
import com.google.android.gms.drive.DriveApi.DriveContentsResult; //导入依赖的package包/类
@Override
public void onResult(DriveContentsResult result) {
if (!result.getStatus().isSuccess()) {
Log.i(TAG, "Error creating new file contents");
return;
}
final DriveContents driveContents = result.getDriveContents();
new Thread() {
@Override
public void run() {
OutputStream outputStream = driveContents.getOutputStream();
addTextfileToOutputStream(outputStream);
MetadataChangeSet changeSet = new MetadataChangeSet.Builder()
.setTitle("testFile")
.setMimeType("text/plain")
.setDescription("This is a text file uploaded from device")
.setStarred(true).build();
Drive.DriveApi.getRootFolder(googleApiClient)
.createFile(googleApiClient, changeSet, driveContents)
.setResultCallback(fileCallback);
}
}.start();
}
开发者ID:JonathanImperato,项目名称:Service-Notes,代码行数:24,代码来源:UploadFileActivity.java
示例2: sync_getFileContents
import com.google.android.gms.drive.DriveApi.DriveContentsResult; //导入依赖的package包/类
/**
* Gets the file contents, see {@link DriveContents}
*
* @param driveFile The Drive file.
* @param openMode The open mode. See {@link DriveFile}
* @param downloadProgressListener If set, opening progress
* information can be show.
* @returns The Drive file contents, see {@link DriveContents}
*/
public DriveContents sync_getFileContents(DriveFile driveFile, int openMode,
DownloadProgressListener downloadProgressListener) throws TBDriveException {
DriveContentsResult result = null;
if(downloadProgressListener!=null) {
result = driveFile.open(getGoogleApiClient(), openMode, downloadProgressListener).await();
}else{
result = driveFile.open(getGoogleApiClient(), openMode, null).await();
}
if (!result.getStatus().isSuccess()) {
//Display an error saying file can't be opened
Log.e(TAG, "Problem opening the file [" + result.getStatus().getStatusMessage() + "].");
throw new TBDriveException("Problem opening the file [" + result.getStatus().getStatusMessage() + "].");
}
//DriveContents object contains pointers to the byte stream
return result.getDriveContents();
}
开发者ID:javocsoft,项目名称:javocsoft-toolbox,代码行数:30,代码来源:TBDrive.java
示例3: async_getFileContents
import com.google.android.gms.drive.DriveApi.DriveContentsResult; //导入依赖的package包/类
/**
* Gets the file contents, see {@link DriveContents}
*
* @param driveFile The Drive file.
* @param openMode The open mode. See {@link DriveFile}
* @param downloadProgressListener If set, opening progress
* information can be show.
* @param callback See {@link TBDriveFileOpenCallback}
*/
public void async_getFileContents(DriveFile driveFile, int openMode,
DownloadProgressListener downloadProgressListener,
final TBDriveFileOpenCallback callback) {
ResultCallback<DriveContentsResult> contentsOpenedCallback =
new ResultCallback<DriveContentsResult>() {
@Override
public void onResult(DriveContentsResult result) {
if (!result.getStatus().isSuccess()) {
// display an error saying file can't be opened
Log.e(TAG, "Problem opening the file [" + result.getStatus().getStatusMessage() + "].");
if(callback!=null) {
callback.setErrorCode(ERROR_FILE_OPEN);
callback.setErrorMessage(ERROR_FILE_OPEN_STRING);
callback.setErrorDetails(result.getStatus().getStatusMessage());
callback.run();
}
return;
}
// DriveContents object contains pointers
// to the actual byte stream
DriveContents contents = result.getDriveContents();
if(callback!=null) {
callback.setDriveContents(contents);
callback.run();
}
}
};
if(downloadProgressListener!=null) {
driveFile.open(getGoogleApiClient(), openMode, downloadProgressListener)
.setResultCallback(contentsOpenedCallback);
}else{
driveFile.open(getGoogleApiClient(), openMode, null)
.setResultCallback(contentsOpenedCallback);
}
}
开发者ID:javocsoft,项目名称:javocsoft-toolbox,代码行数:47,代码来源:TBDrive.java
示例4: uploadFile
import com.google.android.gms.drive.DriveApi.DriveContentsResult; //导入依赖的package包/类
@Override
public int uploadFile(File tempFile) {
DriveFile driveFile;
MetadataResult metadataResult;
Metadata metadata;
DriveContents driveContents = null;
DriveContentsResult driveContentsResult;
OutputStream outputStream;
ExecutionOptions executionOptions;
int complentionStatus;
Log.i(TAG, "start upload of DB file temp:" + tempFile.getName());
try {
driveFile = mDriveId.asDriveFile();
// Get metadata
metadataResult = driveFile.getMetadata(mGoogleApiClient).await();
checkStatus(metadataResult);
metadata = metadataResult.getMetadata();
Log.i(TAG, "try to upload of DB file:" + metadata.getOriginalFilename());
if (!metadata.isPinned()) {
pinFile(driveFile);
}
// Writing file
driveContentsResult = mDriveContent.reopenForWrite(mGoogleApiClient).await();
checkStatus(driveContentsResult);
driveContents = driveContentsResult.getDriveContents();
outputStream = driveContents.getOutputStream();
// Copio il file
FileUtils.copyFile(tempFile, outputStream);
Log.i(TAG, "try to commit file copy done");
// Commit del file
executionOptions = new ExecutionOptions.Builder()
.setNotifyOnCompletion(true)
.setConflictStrategy(ExecutionOptions.CONFLICT_STRATEGY_KEEP_REMOTE)
.build();
driveContents.commit(mGoogleApiClient, null, executionOptions);
Log.i(TAG, "file committed - wait for complention");
// Wait for complention
complentionStatus = mGDriveCompletionRecevier.waitCompletion();
Log.i(TAG, "received complention status:" + complentionStatus);
if (complentionStatus == CompletionEvent.STATUS_CONFLICT) {
return UPLOAD_CONFLICT;
} else if (complentionStatus == CompletionEvent.STATUS_FAILURE) {
throw new SyncException(SyncStatus.Code.ERROR_UPLOAD_CLOUD, "Error writing file to GDrive (FAILURE of commit)");
}
return UPLOAD_OK;
} catch (IOException e) {
if (driveContents != null) {
driveContents.discard(mGoogleApiClient);
}
throw new SyncException(SyncStatus.Code.ERROR_UPLOAD_CLOUD, "Error writing file to GDrive message:" + e.getMessage());
}
}
开发者ID:claudiodegio,项目名称:dbsync,代码行数:70,代码来源:GDriveCloudProvider.java
示例5: downloadFile
import com.google.android.gms.drive.DriveApi.DriveContentsResult; //导入依赖的package包/类
@Override
public InputStream downloadFile() {
DriveFile driveFile;
MetadataResult metadataResult;
Metadata metadata;
DriveContentsResult driveContentsResult;
InputStream inputStream = null;
Log.i(TAG, "start download of DB file");
try {
mDriveContent = null;
driveFile = mDriveId.asDriveFile();
// Get metadata
metadataResult = driveFile.getMetadata(mGoogleApiClient).await();
checkStatus(metadataResult);
// Writing file
driveContentsResult = driveFile.open(mGoogleApiClient, DriveFile.MODE_READ_ONLY, null).await();
checkStatus(driveContentsResult);
metadata = metadataResult.getMetadata();
Log.i(TAG, "downloaded DB file:" + metadata.getOriginalFilename() + " modified on: " + metadata.getModifiedDate() + " size:" + metadata.getFileSize() + " bytes");
mDriveContent = driveContentsResult.getDriveContents();
inputStream = mDriveContent.getInputStream();
if (metadata.getFileSize() < 3) {
inputStream.close();
return null;
}
return inputStream;
} catch (Exception e) {
if (mDriveContent != null) {
mDriveContent.discard(mGoogleApiClient);
}
throw new SyncException(SyncStatus.Code.ERROR_DOWNLOAD_CLOUD, "Error reading file from GDrive message:" + e.getMessage());
}
}
开发者ID:claudiodegio,项目名称:dbsync,代码行数:44,代码来源:GDriveCloudProvider.java
注:本文中的com.google.android.gms.drive.DriveApi.DriveContentsResult类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论