本文整理匯總了Java中com.google.android.gms.drive.DriveId類的典型用法代碼示例。如果您正苦於以下問題:Java DriveId類的具體用法?Java DriveId怎麽用?Java DriveId使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
DriveId類屬於com.google.android.gms.drive包,在下文中一共展示了DriveId類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: saveDriveFile
import com.google.android.gms.drive.DriveId; //導入依賴的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: getContentsFromDrive
import com.google.android.gms.drive.DriveId; //導入依賴的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;
}
示例3: createEmptyDriveFile
import com.google.android.gms.drive.DriveId; //導入依賴的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();
}
示例4: 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();
}
示例5: onActivityResult
import com.google.android.gms.drive.DriveId; //導入依賴的package包/類
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case RESOLVE_CONNECTION_REQUEST_CODE:
if (resultCode == RESULT_OK) {
mGoogleApiClient.connect();
}
break;
case 120:
DriveId driveId = data.getParcelableExtra(OpenFileActivityBuilder.EXTRA_RESPONSE_DRIVE_ID);
new ReadWriteAsync(driveId).execute();
break;
}
}
示例6: onCreate
import com.google.android.gms.drive.DriveId; //導入依賴的package包/類
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addApi(Drive.API)
.addScope(Drive.SCOPE_FILE)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
ButterKnife.bind(this);
mMainHandler = new Handler();
mMainHandler.post(new UpdateCurrentTime());
String driveId = getPreferences(Context.MODE_PRIVATE).getString(DRIVE_ID_FILE, null);
if (driveId != null) {
mDriveId = DriveId.decodeFromString(driveId);
}
}
示例7: onReceive
import com.google.android.gms.drive.DriveId; //導入依賴的package包/類
@Override
public void onReceive(Context context, Intent intent) {
final DriveId driveId = intent.getParcelableExtra(GDriveEventService.BUNDLE_DRIVEID);
Log.i(TAG, "onReceive completion event for driveID:" + driveId.encodeToString());
if (driveId.equals(mDriveId)) {
result = intent.getIntExtra(GDriveEventService.BUNDLE_SUCCESS, -1);
synchronized (this) {
notify();
}
}
}
示例8: onActivityResult
import com.google.android.gms.drive.DriveId; //導入依賴的package包/類
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case AppConstants.EXPORT_RESOLVE_CONNECTION_REQUEST_CODE:
if (resultCode == RESULT_OK) {
mGoogleApiClient.connect();
}
break;
case AppConstants.EXPORT_CREATOR_REQUEST_CODE:
if (resultCode == RESULT_OK) {
DriveId driveFileId = (DriveId) data.getParcelableExtra(
OpenFileActivityBuilder.EXTRA_RESPONSE_DRIVE_ID);
writeDataExportToFile(driveFileId);
}
break;
default:
super.onActivityResult(requestCode, resultCode, data);
break;
}
}
示例9: doInBackgroundConnected
import com.google.android.gms.drive.DriveId; //導入依賴的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;
}
示例10: onActivityResult
import com.google.android.gms.drive.DriveId; //導入依賴的package包/類
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case AppConstants.EXPORT_RESOLVE_CONNECTION_REQUEST_CODE:
if (resultCode == RESULT_OK) {
// mGoogleApiClient.connect();
}
break;
case AppConstants.EXPORT_CREATOR_REQUEST_CODE:
if (resultCode == RESULT_OK) {
DriveId driveFileId = (DriveId) data.getParcelableExtra(
OpenFileActivityBuilder.EXTRA_RESPONSE_DRIVE_ID);
writeDataExportToFile(driveFileId);
}
break;
default:
super.onActivityResult(requestCode, resultCode, data);
break;
}
}
示例11: 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);
}
}
}
示例12: ServiceConnected
import com.google.android.gms.drive.DriveId; //導入依賴的package包/類
@Override
protected void ServiceConnected () {
//File already loaded
if (mFile != null)
return;
Log.i("TextEditor", "Loading content after connection");
Intent intent = getIntent();
//File opened from history
if (intent.hasExtra(INTENT_FILE_ID)) {
long fileId = intent.getLongExtra(INTENT_FILE_ID, -1);
File file = filesHelper.GetItem(fileId);
OpenFile(file);
return;
}
//File opened from drive dialog
if (intent.hasExtra(INTENT_DRIVE_ID)) {
DriveId driveId = intent.getParcelableExtra(INTENT_DRIVE_ID);
OpenDriveFile(driveId);
return;
}
}
示例13: GetItem
import com.google.android.gms.drive.DriveId; //導入依賴的package包/類
public File GetItem(DriveId driveId) {
SQLiteDatabase db = dbHelper.getReadableDatabase();
Cursor cursor = db.query(
DBContracts.FileEntry.TABLE_NAME,
null,
DBContracts.FileEntry.COLUMN_NAME_DRIVE_ID + " = ?",
new String[]{driveId.encodeToString()},
null,
null,
null
);
if (cursor.getCount() != 1)
return null;
cursor.moveToFirst();
File file = CursorToFile(cursor);
cursor.close();
return file;
}
示例14: DownloadFile
import com.google.android.gms.drive.DriveId; //導入依賴的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;
}
});
}
示例15: UploadFileExisting
import com.google.android.gms.drive.DriveId; //導入依賴的package包/類
private void UploadFileExisting(final DriveId driveId, final String contents, final String fileName, final OnFileUploaded callback) {
driveId.asDriveFile().open(getApiClient(), DriveFile.MODE_WRITE_ONLY, null).setResultCallback(new ResultCallback<DriveApi.DriveContentsResult>() {
@Override
public void onResult(DriveApi.DriveContentsResult driveContentsResult) {
Utils.writeToOutputStream(driveContentsResult.getDriveContents().getOutputStream(), contents);
MetadataChangeSet changeSet = new MetadataChangeSet.Builder()
.setTitle(fileName)
.setPinned(true)
.build();
driveContentsResult.getDriveContents().commit(getApiClient(), changeSet).setResultCallback(new ResultCallback<Status>() {
@Override
public void onResult(Status result) {
if (result.getStatus().isSuccess())
callback.onFileUploaded(driveId);
else
callback.onFileUploaded(null);
activeOperations = false;
}
});
}
});
}