当前位置: 首页>>代码示例>>Java>>正文


Java MetadataResult.getMetadata方法代码示例

本文整理汇总了Java中com.google.android.gms.drive.DriveResource.MetadataResult.getMetadata方法的典型用法代码示例。如果您正苦于以下问题:Java MetadataResult.getMetadata方法的具体用法?Java MetadataResult.getMetadata怎么用?Java MetadataResult.getMetadata使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.android.gms.drive.DriveResource.MetadataResult的用法示例。


在下文中一共展示了MetadataResult.getMetadata方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onResult

import com.google.android.gms.drive.DriveResource.MetadataResult; //导入方法依赖的package包/类
@Override
public void onResult(MetadataResult result) {
    if (!result.getStatus().isSuccess()) {
        showMessage("Problem while trying to fetch metadata");
        return;
    }
    Metadata metadata = result.getMetadata();
    showMessage("Metadata successfully fetched. Title: " + metadata.getTitle());
}
 
开发者ID:TerribleDev,项目名称:XamarinAdmobTutorial,代码行数:10,代码来源:RetrieveMetadataActivity.java

示例2: uploadFile

import com.google.android.gms.drive.DriveResource.MetadataResult; //导入方法依赖的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

示例3: downloadFile

import com.google.android.gms.drive.DriveResource.MetadataResult; //导入方法依赖的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

示例4: doInBackgroundConnected

import com.google.android.gms.drive.DriveResource.MetadataResult; //导入方法依赖的package包/类
@Override
protected Metadata doInBackgroundConnected(Void... arg0) {

    // First we start by creating a new contents, and blocking on the
    // result by calling await().
    ContentsResult contentsResult =
            Drive.DriveApi.newContents(getGoogleApiClient()).await();
    if (!contentsResult.getStatus().isSuccess()) {
        // We failed, stop the task and return.
        return null;
    }

    // Read the contents and open its output stream for writing, then
    // write a short message.
    Contents originalContents = contentsResult.getContents();
    OutputStream os = originalContents.getOutputStream();
    try {
        os.write("Hello world!\n".getBytes());
    } catch (IOException e) {
        e.printStackTrace();
        return null;
    }

    // Create the metadata for the new file including title and MIME
    // type.
    MetadataChangeSet originalMetadata = new MetadataChangeSet.Builder()
            .setTitle("AsyncTaskFile.txt")
            .setMimeType("text/plain").build();

    // Create the file in the root folder, again calling await() to
    // block until the request finishes.
    DriveFolder rootFolder = Drive.DriveApi.getRootFolder(getGoogleApiClient());
    DriveFileResult fileResult = rootFolder.createFile(
            getGoogleApiClient(), originalMetadata, originalContents).await();
    if (!fileResult.getStatus().isSuccess()) {
        // We failed, stop the task and return.
        return null;
    }

    // Finally, fetch the metadata for the newly created file, again
    // calling await to block until the request finishes.
    MetadataResult metadataResult = fileResult.getDriveFile()
            .getMetadata(getGoogleApiClient())
            .await();
    if (!metadataResult.getStatus().isSuccess()) {
        // We failed, stop the task and return.
        return null;
    }
    // We succeeded, return the newly created metadata.
    return metadataResult.getMetadata();
}
 
开发者ID:TerribleDev,项目名称:XamarinAdmobTutorial,代码行数:52,代码来源:SyncRequestsActivity.java

示例5: getMetadata

import com.google.android.gms.drive.DriveResource.MetadataResult; //导入方法依赖的package包/类
public Metadata getMetadata(DriveFile mDriveFile) {
	MetadataResult mMetadataResult = mDriveFile.getMetadata(mGoogleApiClient).await();
	if (!mMetadataResult.getStatus().isSuccess()) return null;
	return mMetadataResult.getMetadata();		
}
 
开发者ID:kanpol,项目名称:omni-note,代码行数:6,代码来源:DriveHelper.java


注:本文中的com.google.android.gms.drive.DriveResource.MetadataResult.getMetadata方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。