ファイルを作成するには、これに従って which を送信してみてIntentSender
ください
IntentSender を別のアプリケーションに与えることで、別のアプリケーションが自分自身であるかのように (同じアクセス許可と ID で)、指定した操作を実行する権利をそのアプリケーションに付与します。Pending Intentのように見えます。を使用してファイルを作成できます。
ResultCallback<ContentsResult> onContentsCallback =
new ResultCallback<ContentsResult>() {
@Override
public void onResult(ContentsResult result) {
// TODO: error handling in case of failure
MetadataChangeSet metadataChangeSet = new MetadataChangeSet.Builder()
.setMimeType(MIME_TYPE_TEXT).build();
IntentSender createIntentSender = Drive.DriveApi
.newCreateFileActivityBuilder()
.setInitialMetadata(metadataChangeSet)
.setInitialContents(result.getContents())
.build(mGoogleApiClient);
try {
startIntentSenderForResult(createIntentSender, REQUEST_CODE_CREATOR, null,
0, 0, 0);
} catch (SendIntentException e) {
Log.w(TAG, "Unable to send intent", e);
}
}
};
ここに
`startIntentSenderForResult (IntentSender intent, int requestCode, Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags)`
requestCode >= 0 のonActivityResult()
場合、アクティビティの終了時にこのコードが返されます。あなたonActivityResult()
ができる
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
//REQUEST_CODE_CREATOR == 1
case REQUEST_CODE_CREATOR:
if (resultCode == RESULT_OK) {
DriveId driveId = (DriveId) data.getParcelableExtra(
OpenFileActivityBuilder.EXTRA_RESPONSE_DRIVE_ID);
showMessage("File created with ID: " + driveId);
}
finish();
break;
default:
super.onActivityResult(requestCode, resultCode, data);
break;
}
}
apiClient
このようなものを取得してみてください
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addApi(Drive.API).addScope(Drive.SCOPE_FILE)
.setAccountName(mAccountName).addConnectionCallbacks(this)
.addOnConnectionFailedListener(this).build();
/**
* Called when {@code mGoogleApiClient} is connected.
*/
@Override
public void onConnected(Bundle connectionHint) {
Log.i(TAG, "GoogleApiClient connected");
}
/**
* Called when {@code mGoogleApiClient} is disconnected.
*/
@Override
public void onConnectionSuspended(int cause) {
Log.i(TAG, "GoogleApiClient connection suspended");
}
/**
* Called when {@code mGoogleApiClient} is trying to connect but failed.
* Handle {@code result.getResolution()} if there is a resolution is
* available.
*/
@Override
public void onConnectionFailed(ConnectionResult result) {
Log.i(TAG, "GoogleApiClient connection failed: " + result.toString());
if (!result.hasResolution()) {
GooglePlayServicesUtil.getErrorDialog(result.getErrorCode(), this, 0).show();
return;
}
try {
result.startResolutionForResult(this, REQUEST_CODE_RESOLUTION);
} catch (SendIntentException e) {
Log.e(TAG, "Exception while starting resolution activity", e);
}
}
mAccountName
次のように取得できます。
Account[] accounts = AccountManager.get(this).getAccountsByType("com.google");
if (accounts.length == 0) {
Log.d(TAG, "Must have a Google account installed");
return;
}
mAccountName = accounts[0].name;
お役に立てれば。