本文整理汇总了Java中com.google.android.gms.drive.DriveApi.DriveContentsResult方法的典型用法代码示例。如果您正苦于以下问题:Java DriveApi.DriveContentsResult方法的具体用法?Java DriveApi.DriveContentsResult怎么用?Java DriveApi.DriveContentsResult使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.android.gms.drive.DriveApi
的用法示例。
在下文中一共展示了DriveApi.DriveContentsResult方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: saveDriveFile
import com.google.android.gms.drive.DriveApi; //导入方法依赖的package包/类
/**
* Save the {@code DriveFile} with the specific driveId.
*
* @param id {@link DriveId} of the file.
* @param content The content to be saved in the {@code DriveFile}.
* @return Return value indicates whether the save was successful.
*/
public boolean saveDriveFile(DriveId id, String content) throws IOException {
DriveFile theFile = Drive.DriveApi.getFile(mGoogleApiClient, id);
DriveApi.DriveContentsResult result =
theFile.open(mGoogleApiClient, DriveFile.MODE_WRITE_ONLY, null).await();
try {
IOUtils.writeToStream(content, result.getDriveContents().getOutputStream());
// Update the last viewed.
MetadataChangeSet changeSet = new MetadataChangeSet.Builder()
.setLastViewedByMeDate(new Date())
.build();
return result.getDriveContents().commit(mGoogleApiClient, changeSet)
.await().isSuccess();
} catch (IOException io) {
result.getDriveContents().discard(mGoogleApiClient);
throw io;
}
}
示例2: onResult
import com.google.android.gms.drive.DriveApi; //导入方法依赖的package包/类
@Override
public void onResult(@NonNull DriveApi.DriveContentsResult driveContentsResult) {
try {
InputStream inputStream = driveContentsResult.getDriveContents().getInputStream();
byte[] b = new byte[4096];
String current = "";
int read = 0;
while ((read = inputStream.read(b, 0, 4096)) != -1)
current += new String(b, 0, read);
if (current.length() > 0)
DataManager.saveJsonAsData(new JSONObject(current));
driveContentsResult.getDriveContents().reopenForWrite(mGoogleApiClient).setResultCallback(writeDriveCallback);
} catch (IOException | JSONException e) {
Toast.makeText(getApplicationContext(), getString(R.string.drive_fail_get_data), Toast.LENGTH_LONG).show();
}
}
示例3: getContentsFromDrive
import com.google.android.gms.drive.DriveApi; //导入方法依赖的package包/类
public String getContentsFromDrive(DriveId id) throws IOException {
DriveFile theFile = Drive.DriveApi.getFile(mGoogleApiClient, id);
DriveApi.DriveContentsResult result =
theFile.open(mGoogleApiClient, DriveFile.MODE_READ_ONLY, null).await();
DriveContents driveContents = result.getDriveContents();
try {
if (driveContents != null) {
return IOUtils.readAsString(driveContents.getInputStream());
}
} finally {
if (driveContents != null) {
driveContents.discard(mGoogleApiClient);
}
}
return null;
}
示例4: createEmptyDriveFile
import com.google.android.gms.drive.DriveApi; //导入方法依赖的package包/类
/**
* Create an empty file with the given {@code fileName} and {@code mimeType}.
*
* @return {@link DriveId} of the specific file.
*/
private DriveId createEmptyDriveFile(String fileName, String mimeType) {
DriveApi.DriveContentsResult result =
Drive.DriveApi.newDriveContents(mGoogleApiClient).await();
MetadataChangeSet changeSet = new MetadataChangeSet.Builder()
.setTitle(fileName)
.setMimeType(mimeType)
.setStarred(true)
.build();
// Create a new file with the given changeSet in the AppData folder.
DriveFolder.DriveFileResult driveFileResult = Drive.DriveApi.getAppFolder(mGoogleApiClient)
.createFile(mGoogleApiClient, changeSet, result.getDriveContents())
.await();
return driveFileResult.getDriveFile().getDriveId();
}
示例5: doInBackgroundConnected
import com.google.android.gms.drive.DriveApi; //导入方法依赖的package包/类
@Override
protected Boolean doInBackgroundConnected(EditContentParams... args) {
DriveFile file = args[0].getFileToWrite();
String dataToWrite = args[0].getDataToWrite();
try {
DriveApi.DriveContentsResult driveContentsResult = file.open(
getGoogleApiClient(), DriveFile.MODE_WRITE_ONLY, null).await();
if (!driveContentsResult.getStatus().isSuccess()) {
return false;
}
DriveContents driveContents = driveContentsResult.getDriveContents();
OutputStream outputStream = driveContents.getOutputStream();
outputStream.write(dataToWrite.getBytes());
com.google.android.gms.common.api.Status status =
driveContents.commit(getGoogleApiClient(), null).await();
return status.getStatus().isSuccess();
} catch (IOException e) {
AppUtils.showMessage(context,"Failed to write data to file.");
}
return false;
}
示例6: doInBackgroundConnected
import com.google.android.gms.drive.DriveApi; //导入方法依赖的package包/类
@Override
protected String doInBackgroundConnected(DriveId... params) {
String contents = null;
DriveFile file = params[0].asDriveFile();
DriveApi.DriveContentsResult driveContentsResult =
file.open(getGoogleApiClient(), DriveFile.MODE_READ_ONLY, null).await();
if (!driveContentsResult.getStatus().isSuccess()) {
return null;
}
DriveContents driveContents = driveContentsResult.getDriveContents();
BufferedReader reader = new BufferedReader(
new InputStreamReader(driveContents.getInputStream()));
StringBuilder builder = new StringBuilder();
String line;
try {
while ((line = reader.readLine()) != null) {
builder.append(line);
}
contents = builder.toString();
} catch (IOException e) {
Log.e(TAG, "IOException while reading from the stream", e);
}
driveContents.discard(getGoogleApiClient());
return contents;
}
示例7: doInBackgroundConnected
import com.google.android.gms.drive.DriveApi; //导入方法依赖的package包/类
@Override
protected Boolean doInBackgroundConnected(DriveFile... args) {
DriveFile file = args[0];
try {
DriveApi.DriveContentsResult driveContentsResult = file.open(
getGoogleApiClient(), DriveFile.MODE_WRITE_ONLY, null).await();
if (!driveContentsResult.getStatus().isSuccess()) {
return false;
}
DriveContents driveContents = driveContentsResult.getDriveContents();
OutputStream outputStream = driveContents.getOutputStream();
outputStream.write(Helpers.getSMSJson(context).getBytes());
com.google.android.gms.common.api.Status status =
driveContents.commit(getGoogleApiClient(), null).await();
return status.getStatus().isSuccess();
} catch (IOException e) {
Log.e(TAG, "IOException while appending to the output stream", e);
}
return false;
}
示例8: onFileResultsReady
import com.google.android.gms.drive.DriveApi; //导入方法依赖的package包/类
/**
* Handles the DriveContentsResult returned from the request to get the DriveFile of the
* Database.
*
* @param result the DriveContentsResult representing the Drive copy of the Database
*/
@Override
public void onFileResultsReady(DriveApi.DriveContentsResult result) {
if (!mDriveClient.isConnected()) {
mDriveClient.connect();
}
this.result = result;
int which = deQueue();
switch (which) {
case PUT:
writeLocalDbToCloudStream(result.getDriveContents().getOutputStream());
result.getDriveContents().commit(mDriveClient, null);
break;
case GET:
writeCloudStreamToLocalDb(result.getDriveContents().getInputStream());
break;
}
if (ongoingRequest) {
mDriveLayer.getFile(localDb.getName());
}
}
示例9: onFileResultsReady
import com.google.android.gms.drive.DriveApi; //导入方法依赖的package包/类
/**
* Handles the DriveContentsResult returned from the request to get the DriveFile of the
* Database.
* @param result the DriveContentsResult representing the Drive copy of the Database
*/
@Override
public void onFileResultsReady(DriveApi.DriveContentsResult result) {
if (!mDriveClient.isConnected()) {
mDriveClient.connect();
}
this.result = result;
int which = deQueue();
switch (which) {
case PUT:
writeLocalDbToCloudStream(result.getDriveContents().getOutputStream());
result.getDriveContents().commit(mDriveClient, null);
break;
case GET:
writeCloudStreamToLocalDb(result.getDriveContents().getInputStream());
break;
}
if (ongoingRequest) {
mDriveLayer.getFile(localDb.getName());
}
}
示例10: DownloadFile
import com.google.android.gms.drive.DriveApi; //导入方法依赖的package包/类
public void DownloadFile(DriveId driveId, final OnFileDownloaded callback) {
activeOperations = true;
PendingResult<DriveApi.DriveContentsResult> contentsResult = driveId.asDriveFile().open(getApiClient(), DriveFile.MODE_READ_ONLY, null);
contentsResult.setResultCallback(new ResultCallback<DriveApi.DriveContentsResult>() {
@Override
public void onResult(DriveApi.DriveContentsResult driveContentsResult) {
Log.d("DocumentList", "In file open");
if (driveContentsResult.getDriveContents() == null) {
//There is no file
callback.onFileDownloaded(null);
activeOperations = false;
return;
}
callback.onFileDownloaded(Utils.readFromInputStream(driveContentsResult.getDriveContents().getInputStream()));
activeOperations = false;
}
});
}
示例11: onResult
import com.google.android.gms.drive.DriveApi; //导入方法依赖的package包/类
@Override
public void onResult(DriveApi.DriveContentsResult result) {
MetadataChangeSet metadataChangeSet = new MetadataChangeSet.Builder()
.setTitle("cumulustv_channels.json")
.setDescription("JSON list of channels that can be imported using CumulusTV to view live streams")
.setMimeType("application/json").build();
IntentSender intentSender = Drive.DriveApi
.newCreateFileActivityBuilder()
.setActivityTitle("cumulustv_channels.json")
.setInitialMetadata(metadataChangeSet)
.setInitialDriveContents(result.getDriveContents())
.build(CloudStorageProvider.getInstance().getClient());
try {
mActivity.startIntentSenderForResult(
intentSender, REQUEST_CODE_CREATOR, null, 0, 0, 0);
} catch (IntentSender.SendIntentException e) {
Log.w(TAG, "Unable to send intent", e);
}
}
示例12: createDriveData
import com.google.android.gms.drive.DriveApi; //导入方法依赖的package包/类
public static void createDriveData(Activity activity, GoogleApiClient gapi,
final ResultCallback<DriveApi.DriveContentsResult> driveContentsCallback) {
PermissionUtils.requestPermissionIfDisabled(activity,
android.Manifest.permission.WRITE_EXTERNAL_STORAGE,
activity.getString(R.string.permission_storage_rationale));
if(gapi == null)
gapi = mCloudStorageProvider.connect(activity);
try {
final GoogleApiClient finalGapi = gapi;
new AlertDialog.Builder(activity)
.setTitle(R.string.create_sync_file_title)
.setMessage(R.string.create_sync_file_description)
.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
Drive.DriveApi.newDriveContents(finalGapi)
.setResultCallback(driveContentsCallback);
}
})
.setNegativeButton(R.string.no, null)
.show();
} catch(Exception ignored) {
Toast.makeText(activity, "Error creating drive data: " + ignored.getMessage(),
Toast.LENGTH_SHORT).show();
}
}
示例13: onResult
import com.google.android.gms.drive.DriveApi; //导入方法依赖的package包/类
@Override
public void onResult(DriveApi.DriveContentsResult result) {
MetadataChangeSet metadataChangeSet = new MetadataChangeSet.Builder()
.setTitle("cumulustv_channels.json")
.setDescription("JSON list of channels that can be imported using " +
"CumulusTV to view live streams")
.setMimeType("application/json").build();
IntentSender intentSender = Drive.DriveApi
.newCreateFileActivityBuilder()
.setActivityTitle("cumulustv_channels.json")
.setInitialMetadata(metadataChangeSet)
.setInitialDriveContents(result.getDriveContents())
.build(CloudStorageProvider.getInstance().getClient());
try {
startIntentSenderForResult(
intentSender, REQUEST_CODE_CREATOR, null, 0, 0, 0);
} catch (IntentSender.SendIntentException e) {
Log.w(TAG, "Unable to send intent", e);
}
}
示例14: onResult
import com.google.android.gms.drive.DriveApi; //导入方法依赖的package包/类
@Override
public void onResult(@NonNull DriveApi.DriveContentsResult result) {
if(result.getStatus().isSuccess()) {
try {
FileDescriptor file = result.getDriveContents()
.getParcelFileDescriptor().getFileDescriptor();
FileInputStream fis = new FileInputStream(file);
mData = new byte[fis.available()];
int nbr = fis.read(mData);
fis.close();
if(nbr < mData.length) {
mListener.onSyncFailed(CA.DATA_RECEIVED);
return;
}
mListener.onSyncProgress(CA.DATA_RECEIVED);
}catch(IOException e) {
mListener.onSyncFailed(CA.DATA_RECEIVED);
Log.w(LOG_TAG, "Reading contents received IOException");
}
}
else {
mListener.onSyncFailed(CA.NO_DATA);
Log.w(LOG_TAG, "Retrieving contents received error");
}
}
示例15: onNewContents
import com.google.android.gms.drive.DriveApi; //导入方法依赖的package包/类
public void onNewContents(DriveApi.DriveContentsResult result)
{
if (!result.getStatus().isSuccess())
{
Toast.makeText(App.getAppContext(), "Error while trying to create new file contents", Toast.LENGTH_SHORT).show();
return;
}
MetadataChangeSet changeSet = new MetadataChangeSet.Builder()
.setTitle("Finanvita " + DateUtils.formatDateTime(App.getAppContext(), System.currentTimeMillis(), DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_YEAR))
.setMimeType("application/json")
.setStarred(false).build();
Drive.DriveApi.getRootFolder(client).createFile(client, changeSet, result.getDriveContents()).setResultCallback(new ResultCallback<DriveFolder.DriveFileResult>() {
@Override
public void onResult(DriveFolder.DriveFileResult driveFileResult) {
onCreateFile(driveFileResult);
}
});
}