本文整理汇总了Java中com.google.android.gms.drive.Drive类的典型用法代码示例。如果您正苦于以下问题:Java Drive类的具体用法?Java Drive怎么用?Java Drive使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Drive类属于com.google.android.gms.drive包,在下文中一共展示了Drive类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: saveDriveFile
import com.google.android.gms.drive.Drive; //导入依赖的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.Drive; //导入依赖的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();
}
示例3: FindOrCreateDriveFile
import com.google.android.gms.drive.Drive; //导入依赖的package包/类
void FindOrCreateDriveFile(){
// Check if we already have a driveID file
Context context = getApplicationContext();
SharedPreferences mSharedPreferences = context.getSharedPreferences(PREFERENCES_NAME, Context.MODE_PRIVATE);
sPreviousDriveID = mSharedPreferences.getString(PREF_DRIVE_ID,"");
if (sPreviousDriveID.length() > 0){
Log.v(TAG, "Using saved drive ID: " + sPreviousDriveID);
Drive.DriveApi.fetchDriveId(getGoogleApiClient(),sPreviousDriveID)
.setResultCallback(driveFetchIDCallback);
} else {
// create new contents resource
Log.v(TAG, "Attempting to create new drive file");
Drive.DriveApi.newDriveContents(getGoogleApiClient())
.setResultCallback(driveContentsCallback);
}
}
示例4: initialize
import com.google.android.gms.drive.Drive; //导入依赖的package包/类
/**
* Initializes the GoogleApiClient. Give your main AndroidLauncher as context.
* <p>
* Don't forget to add onActivityResult method there with call to onGpgsActivityResult.
*
* @param context your AndroidLauncher class
* @param enableDriveAPI true if you activate save gamestate feature
* @return this for method chunking
*/
public GpgsClient initialize(Activity context, boolean enableDriveAPI) {
if (mGoogleApiClient != null)
throw new IllegalStateException("Already initialized.");
myContext = context;
// retry some times when connect fails (needed when game state sync is enabled)
firstConnectAttempt = MAX_CONNECTFAIL_RETRIES;
GoogleApiClient.Builder builder = new GoogleApiClient.Builder(myContext)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(Games.API).addScope(Games.SCOPE_GAMES);
driveApiEnabled = enableDriveAPI;
if (driveApiEnabled)
builder.addApi(Drive.API).addScope(Drive.SCOPE_APPFOLDER);
// add other APIs and scopes here as needed
mGoogleApiClient = builder.build();
return this;
}
示例5: createApiClientBuilder
import com.google.android.gms.drive.Drive; //导入依赖的package包/类
/**
* Creates a GoogleApiClient.Builder for use with @link{#setup}. Normally,
* you do not have to do this; use this method only if you need to make
* nonstandard setup (e.g. adding extra scopes for other APIs) on the
* GoogleApiClient.Builder before calling @link{#setup}.
*/
public GoogleApiClient.Builder createApiClientBuilder() {
if (mSetupDone) {
String error = "GameHelper: you called GameHelper.createApiClientBuilder() after "
+ "calling setup. You can only get a client builder BEFORE performing setup.";
logError(error);
throw new IllegalStateException(error);
}
GoogleApiClient.Builder builder = new GoogleApiClient.Builder(
mActivity, this, this);
if (0 != (mRequestedClients & CLIENT_GAMES)) {
builder.addApi(Games.API, mGamesApiOptions);
builder.addScope(Games.SCOPE_GAMES);
}
if (0 != (mRequestedClients & CLIENT_SNAPSHOT)) {
builder.addScope(Drive.SCOPE_APPFOLDER);
builder.addApi(Drive.API);
}
mGoogleApiClientBuilder = builder;
return builder;
}
示例6: init
import com.google.android.gms.drive.Drive; //导入依赖的package包/类
public void init() {
final Client thisReference = this;
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
debugLog("Client.init : initializing Google Play Game Services...");
googleApiClient = new GoogleApiClient.Builder(getActivity())
.addConnectionCallbacks(thisReference)
.addOnConnectionFailedListener(thisReference)
.addApi(Games.API).addScope(Games.SCOPE_GAMES)
.addApi(Plus.API).addScope(Plus.SCOPE_PLUS_LOGIN)
.addApi(Drive.API).addScope(Drive.SCOPE_APPFOLDER)
.build();
}
});
}
示例7: getContentsFromDrive
import com.google.android.gms.drive.Drive; //导入依赖的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;
}
示例8: createEmptyDriveFile
import com.google.android.gms.drive.Drive; //导入依赖的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();
}
示例9: commitToNewFile
import com.google.android.gms.drive.Drive; //导入依赖的package包/类
/**
* Creates a new file and adds the {@link DriveContents} passed to this method.
* @return Returns a boolean stating the success of this operation
*/
private boolean commitToNewFile(DriveContents driveContents) {
DebugLog.logMethod();
MetadataChangeSet changeSet = new MetadataChangeSet.Builder()
.setTitle("CouponsTrackerData.txt")
.setMimeType("text/plain")
.build();
DriveFolder.DriveFileResult driveFileResult = Drive.DriveApi
.getAppFolder(getGoogleApiClient())
.createFile(getGoogleApiClient(), changeSet, driveContents)
.await();
DebugLog.logMessage("DriveFileResult: statusCode - " + driveFileResult.getStatus().getStatusCode()
+ ", statusMessage: " + driveFileResult.getStatus().getStatusMessage());
return driveFileResult.getStatus().isSuccess();
}
示例10: getDriveFile
import com.google.android.gms.drive.Drive; //导入依赖的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();
}
示例11: onResult
import com.google.android.gms.drive.Drive; //导入依赖的package包/类
@Override
public void onResult(@NonNull final DriveApi.DriveContentsResult driveContentsResult) {
new Thread(new Runnable() {
@Override
public void run() {
DriveFolder appFolder = Drive.DriveApi.getAppFolder(mGoogleApiClient);
MetadataChangeSet set = new MetadataChangeSet.Builder().setTitle(getString(R.string.drive_file_name)).setMimeType(getString(R.string.drive_file_mimetype)).build();
appFolder.createFile(mGoogleApiClient, set, driveContentsResult.getDriveContents()).setResultCallback(new ResultCallback<DriveFolder.DriveFileResult>() {
@Override
public void onResult(@NonNull DriveFolder.DriveFileResult driveFileResult) {
driveFileResult.getDriveFile().open(mGoogleApiClient, DriveFile.MODE_WRITE_ONLY, null).setResultCallback(writeDriveCallback);
loadingView.setVisibility(View.GONE);
}
});
}
}).start();
}
示例12: onCreate
import com.google.android.gms.drive.Drive; //导入依赖的package包/类
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test_gdrive_activity);
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addApi(Drive.API)
.addScope(Drive.SCOPE_FILE)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
ButterKnife.bind(this);
init();
}
示例13: onCreate
import com.google.android.gms.drive.Drive; //导入依赖的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);
}
}
示例14: actionCreateFileForSync
import com.google.android.gms.drive.Drive; //导入依赖的package包/类
@OnClick(R.id.btCreateFileForSync)
public void actionCreateFileForSync() {
try {
MetadataChangeSet metadataChangeSet = new MetadataChangeSet.Builder()
.setMimeType("text/plain").build();
IntentSender intentSender = Drive.DriveApi.newCreateFileActivityBuilder()
.setInitialMetadata(metadataChangeSet)
.setInitialDriveContents(null)
.setActivityTitle("Create file for sync")
.build(mGoogleApiClient);
startIntentSenderForResult(intentSender, REQUEST_CODE_NEW_FILE, null, 0, 0, 0);
} catch (Exception e) {
Log.w(TAG, "Unable to send intent", e);
}
}
示例15: showGDriveFolderSelector
import com.google.android.gms.drive.Drive; //导入依赖的package包/类
private static void showGDriveFolderSelector(Activity activity) {
if (activity == null)
return;
OpenFileActivityBuilder openFileActivityBuilder = Drive.DriveApi
.newOpenFileActivityBuilder();
if (openFileActivityBuilder != null) {
IntentSender intentSender = openFileActivityBuilder.setActivityTitle(AndiCar.getAppResources().getString(R.string.pref_secure_backup_gdrive_folder_selector_title))
.setSelectionFilter(Filters.eq(SearchableField.MIME_TYPE, DriveFolder.MIME_TYPE))
.build(mGoogleApiClient);
try {
activity.startIntentSenderForResult(
intentSender, ConstantValues.REQUEST_OPEN_DRIVE_FOLDER, null, 0, 0, 0);
}
catch (IntentSender.SendIntentException e) {
Log.i("AndiCar", "Failed to launch file chooser.");
}
}
else {
Toast.makeText(activity, "Unable to open folder selector!", Toast.LENGTH_LONG).show();
}
}