私はアンドロイドアプリにgoogleドライブを正常に統合しました。しかし、選択した画像ファイルをダウンロードできませんでした。 ここに私のコードです。結果のコールバックメソッドが決して実行されないという問題があります。親切に私を助けてください。また、私はdata.getData()メソッドonActivityの結果このメソッドだけを使用返品nullを使用しました。私はイメージのURIをどのように見つけることができますか?ダウンロードGoogleドライブAndroid APIからの画像?
package com.example.syedfurqan.dropboxintegration;
import android.app.Activity;
import android.content.Intent;
import android.content.IntentSender;
import android.content.IntentSender.SendIntentException;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.widget.ImageView;
import android.widget.Toast;
import com.dropbox.chooser.android.DbxChooser;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GoogleApiAvailability;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.common.api.PendingResult;
import com.google.android.gms.common.api.ResultCallback;
import com.google.android.gms.drive.Drive;
import com.google.android.gms.drive.DriveApi;
import com.google.android.gms.drive.DriveContents;
import com.google.android.gms.drive.DriveFile;
import com.google.android.gms.drive.DriveId;
import com.google.android.gms.drive.DriveResource;
import com.google.android.gms.drive.Metadata;
import com.google.android.gms.drive.OpenFileActivityBuilder;
import java.io.InputStream;
public class BaseDemoActivity extends Activity implements
GoogleApiClient.ConnectionCallbacks,
GoogleApiClient.OnConnectionFailedListener {
private static final String TAG = "BaseDriveActivity";
protected static final int REQUEST_CODE_RESOLUTION = 1;
private static final int REQ_CODE_OPEN = 2;
private GoogleApiClient mGoogleApiClient;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// setContentView(R.layout.activity_base_demo);
if (mGoogleApiClient == null) {
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addApi(Drive.API)
.addScope(Drive.SCOPE_FILE)
.addScope(Drive.SCOPE_APPFOLDER)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
}
mGoogleApiClient.connect();
}
@Override
protected void onActivityResult(int requestCode, int resultCode,
Intent data) {
switch (requestCode) {
case REQ_CODE_OPEN:
if (resultCode == RESULT_OK) {
DriveId mFileId = (DriveId) data
.getParcelableExtra(OpenFileActivityBuilder.EXTRA_RESPONSE_DRIVE_ID);
DriveFile selectedFile = mFileId.asDriveFile();
selectedFile.open(mGoogleApiClient, DriveFile.MODE_READ_ONLY, null)
.setResultCallback(idCallback);
} else {
finish();
}
break;
default:
super.onActivityResult(requestCode, resultCode, data);
}
}
@Override
protected void onPause() {
if (mGoogleApiClient != null) {
mGoogleApiClient.disconnect();
}
super.onPause();
}
//Picker
@Override
public void onConnected(Bundle connectionHint) {
Log.i(TAG, "GoogleApiClient connected");
// Launch user interface and allow user to select file
try {
IntentSender i = Drive.DriveApi
.newOpenFileActivityBuilder()
.setMimeType(new String[]{"image/png", "image/jpeg"})
.build(mGoogleApiClient);
startIntentSenderForResult(i, REQ_CODE_OPEN, null, 0, 0, 0);
} catch (Exception e) {
}
}
final private ResultCallback<DriveApi.DriveContentsResult> idCallback = new ResultCallback<DriveApi.DriveContentsResult>() {
@Override
public void onResult(DriveApi.DriveContentsResult result) {
if (!result.getStatus().isSuccess()) {
// Handle an error
}
DriveContents driveContents = result.getDriveContents();
InputStream is = driveContents.getInputStream();
Bitmap bitmap = BitmapFactory.decodeStream(is);
Values.setBitmap(bitmap);
}
};
@Override
public void onConnectionSuspended(int cause) {
Log.i(TAG, "GoogleApiClient connection suspended");
}
@Override
public void onConnectionFailed(ConnectionResult result) {
Log.i(TAG, "GoogleApiClient connection failed: " + result.toString());
if (!result.hasResolution()) {
// show the localized error dialog.
GoogleApiAvailability.getInstance().getErrorDialog(this, result.getErrorCode(), 0).show();
return;
}
try {
result.startResolutionForResult(this, REQUEST_CODE_RESOLUTION);
} catch (SendIntentException e) {
Log.e(TAG, "Exception while starting resolution activity", e);
}
}
/**
* Shows a toast message.
*/
public void showMessage(String message) {
Toast.makeText(this, message, Toast.LENGTH_LONG).show();
}
/**
* Getter for the {@code GoogleApiClient}.
*/
public GoogleApiClient getGoogleApiClient() {
return mGoogleApiClient;
}
}
.. :)だから、素晴らしい – Furqan