本文整理匯總了Java中com.google.android.gms.drive.DriveId.asDriveFile方法的典型用法代碼示例。如果您正苦於以下問題:Java DriveId.asDriveFile方法的具體用法?Java DriveId.asDriveFile怎麽用?Java DriveId.asDriveFile使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.google.android.gms.drive.DriveId
的用法示例。
在下文中一共展示了DriveId.asDriveFile方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getDriveFile
import com.google.android.gms.drive.DriveId; //導入方法依賴的package包/類
/**
* Returns the app specific {@link DriveFile} if it has already been created. Else
* returns null.
*/
protected final DriveFile getDriveFile() {
DebugLog.logMethod();
DriveApi.MetadataBufferResult metadataBufferResult = Drive.DriveApi.getAppFolder(getGoogleApiClient())
.listChildren(getGoogleApiClient())
.await();
DebugLog.logMessage("Status code: " + metadataBufferResult.getStatus().getStatusCode()
+ "\nStatus message: " + metadataBufferResult.getStatus().getStatusMessage());
if (!metadataBufferResult.getStatus().isSuccess()) {
metadataBufferResult.release();
DebugLog.logMessage("MetadataBufferResult failure");
return null;
}
MetadataBuffer metadataBuffer = metadataBufferResult.getMetadataBuffer();
DebugLog.logMessage("MetadataBuffer count: " + metadataBuffer.getCount());
if (metadataBuffer.getCount() == 0) {
metadataBuffer.release();
return null;
}
DriveId driveId = metadataBuffer.get(0).getDriveId();
metadataBuffer.release();
metadataBufferResult.release();
return driveId.asDriveFile();
}
示例2: onActivityResult
import com.google.android.gms.drive.DriveId; //導入方法依賴的package包/類
@Override
protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
switch (requestCode) {
case REQUEST_CODE_CREATOR:
// Called after a file is saved to Drive.
if (resultCode == RESULT_OK) {
Log.i(TAG, "Backup successfully saved.");
Toast.makeText(this, "Backup successufly loaded!", Toast.LENGTH_SHORT).show();
}
break;
case REQUEST_CODE_OPENER:
if (resultCode == RESULT_OK) {
DriveId driveId = data.getParcelableExtra(
OpenFileActivityBuilder.EXTRA_RESPONSE_DRIVE_ID);
//Toast.makeText(this, driveId.toString(), Toast.LENGTH_SHORT).show();
DriveFile file = driveId.asDriveFile();
importFromDrive(file);
}
}
}
示例3: onResult
import com.google.android.gms.drive.DriveId; //導入方法依賴的package包/類
@Override
public void onResult(DriveFolder.DriveFileResult result) {
mConnectionRequested = false; // for testing
if (!result.getStatus().isSuccess()) {
showMessage("Error while trying to create the file");
return;
}
DriveId driveId = result.getDriveFile().getDriveId();
showMessage("Created file: " + driveId);
if (LDebug.ON) Log.d(LOG_TAG, "XXX Created file: " + driveId);
DriveFile file = driveId.asDriveFile();
file.addChangeSubscription(getGoogleApiClient());
if (LDebug.ON) Log.d(LOG_TAG, "XXX resource ID file: "
+ result.getDriveFile().getDriveId().getResourceId()); // returns null
// result.getDriveFile().getMetadata().isCanceled();
}
示例4: writeDataExportToFile
import com.google.android.gms.drive.DriveId; //導入方法依賴的package包/類
private void writeDataExportToFile(DriveId driveFileId) {
EditContentParams params = new EditContentParams(
new ExportDataManager(TheHubActivity.this).readFileByInputStream(),
driveFileId.asDriveFile()
);
new EditContentsAsyncTask(this).execute(params);
}
示例5: readFileFromDrive
import com.google.android.gms.drive.DriveId; //導入方法依賴的package包/類
/**
* Create a new file and save it to Drive.
*/
private void readFileFromDrive(DriveId id) {
final DriveFile f = id.asDriveFile();
EXECUTOR_SERVICE.execute(() -> {
DriveApi.DriveContentsResult driveContentsResult =
f.open(mGoogleApiClient, DriveFile.MODE_READ_ONLY,
null).await();
if (!driveContentsResult.getStatus().isSuccess()) {
if (BuildConfig.DEBUG)
Log.d(TAG, "readFileFromDrive: " + driveContentsResult.getStatus());
return;
}
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);
}
String contentsAsString = builder.toString();
Gson gson = new Gson();
NoteLab noteLab = gson.fromJson(contentsAsString, NoteLab.class);
if (noteLab == null) {
return;
}
if (BuildConfig.DEBUG)
Log.i(TAG, "readFileFromDrive: " + noteLab.getMoonlights().size());
mFDatabaseUtils.restoreAll(noteLab);
} catch (IOException e) {
Log.e(TAG, "readFileFromDrive: IOException while reading from the stream, ", e);
}
driveContents.discard(mGoogleApiClient);
});
}
示例6: onResult
import com.google.android.gms.drive.DriveId; //導入方法依賴的package包/類
@Override
public void onResult(DriveApi.MetadataBufferResult result) {
if (!result.getStatus().isSuccess()) {
showMessage("Problem while retrieving files");
return;
}
if (result.getMetadataBuffer().getCount() == 0) {
//now create a new file as it doesn't exist
if (type != Constants.TYPE_RESTORE)
createFile();
else
showMessage("No backup found");
return;
}
DriveId driveId = result.getMetadataBuffer().get(0).getDriveId();
if (type == Constants.TYPE_RESTORE){
//for retrieving the content of the file
new RetrieveDriveFileContentsAsyncTask(SettingsActivity.this).execute(driveId);
}
else{
//for editing the content of the file
DriveFile file = driveId.asDriveFile();
new EditContentsAsyncTask(SettingsActivity.this).execute(file);
}
}
示例7: deleteSavedEquations
import com.google.android.gms.drive.DriveId; //導入方法依賴的package包/類
/**
* Deletes the App Data file associated with the {@link DriveId} in {@link SharedPreferences}, if
* it exists.
*/
private void deleteSavedEquations() {
final String driveIdStr = mSharedPreferences.getString(DRIVE_ID, null);
if (driveIdStr != null) {
DriveId fileId = DriveId.decodeFromString(driveIdStr);
// [START delete_file]
// Delete App Data file
DriveFile sumFile = fileId.asDriveFile();
mDriveResourceClient.delete(sumFile)
.addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
// Delete completed successfully. UI changes, etc. can now be updated to reflect the
// change.
// [START_EXCLUDE]
// Remove stored DriveId from SharedPreferences
mSharedPreferences.edit().remove(DRIVE_ID).apply();
Log.d(TAG, "Past sums deleted.");
// [END_EXCLUDE]
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
// Delete was not completed. Inform the user or add failure handling here.
// [START_EXCLUDE]
Log.e(TAG, "Unable to delete App Data.", e);
// [END_EXCLUDE]
}
});
// [END delete_file]
}
}