Ich versuche, meine App bei Google Play-Dienst zu verbinden Google Drive zugreifen, aber es zeigt mir Verbindung fehlgeschlagen mit status SIGN_IN_REQUIRED.
GoogleApiClient onConnectionFailed mit status = SIGN_IN_REQUIRED
Aber es scheint so, dass nur 3 Tagen zu verhalten vor. Ich habe auch die Entwicklerkonsole von Google überprüft. Sie haben möglicherweise etwas in der API geändert, das ich nicht herausfinden kann. Ihre Hilfe wird willkommen sein.
Mein Code:
/**
* Create a new file and save it to Drive.
*/
private void saveFileToDrive(final byte[] data) {
// Start by creating a new contents, and setting a callback.
Log.i(TAG, "Creating new contents.");
//final Bitmap image = mBitmapToSave;
Drive.DriveApi.newDriveContents(mGoogleApiClient)
.setResultCallback(new ResultCallback<DriveApi.DriveContentsResult>() {
@Override
public void onResult(DriveApi.DriveContentsResult result) {
// If the operation was not successful, we cannot do anything
// and must
// fail.
if (!result.getStatus().isSuccess()) {
Log.i(TAG, "Failed to create new contents.");
return;
}
// Otherwise, we can write our data to the new contents.
Log.i(TAG, "New contents created.");
// Get an output stream for the contents.
OutputStream outputStream = result.getDriveContents().getOutputStream();
// Write the bitmap data from it.
/* ByteArrayOutputStream bitmapStream = new ByteArrayOutputStream();
image.compress(Bitmap.CompressFormat.PNG, 100, bitmapStream);*/
try {
//outputStream.write(bitmapStream.toByteArray());
outputStream.write(data);
} catch (IOException e1) {
Log.i(TAG, "Unable to write file contents.");
}
// Create the initial metadata - MIME type and title.
// Note that the user will be able to change the title later.
MetadataChangeSet metadataChangeSet = new MetadataChangeSet.Builder()
.setMimeType("application/pdf").setTitle(filename).build();
// Create an intent for the file chooser, and start it.
IntentSender intentSender = Drive.DriveApi
.newCreateFileActivityBuilder()
.setInitialMetadata(metadataChangeSet)
.setInitialDriveContents(result.getDriveContents())
.build(mGoogleApiClient);
try {
startIntentSenderForResult(
intentSender, REQUEST_CODE_CREATOR, null, 0, 0, 0);
} catch (IntentSender.SendIntentException e) {
Log.i(TAG, "Failed to launch file chooser.");
}
}
});
}
@Override
protected void onResume() {
super.onResume();
if (mGoogleApiClient == null) {
// Create the API client and bind it to an instance variable.
// We use this instance as the callback for connection and connection
// failures.
// Since no account name is passed, the user is prompted to choose.
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addApi(Drive.API)
.addScope(Drive.SCOPE_FILE)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
}
// Connect the client. Once connected, the camera is launched.
mGoogleApiClient.connect();
}
@Override
protected void onPause() {
if (mGoogleApiClient != null) {
mGoogleApiClient.disconnect();
}
super.onPause();
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case REQUEST_CODE_CREATOR:
// Called after a file is saved to Drive.
if (resultCode == RESULT_OK) {
Log.i(TAG, "Image successfully saved.");
Intent intent = new Intent();
intent.putExtra("FILE_PATH",file_path);
PreviewActivity.this.setResult(RESULT_OK, intent);
finish();
progressDialog.hide();
}
break;
}
}
@Override
public void onConnected(Bundle bundle) {
Log.i(TAG, "API client connected.");
//saveFileToDrive();
}
@Override
public void onConnectionSuspended(int i) {
Log.i(TAG, "GoogleApiClient connection suspended");
}
@Override
public void onConnectionFailed(ConnectionResult connectionResult) {
// Called whenever the API client fails to connect.
Log.i(TAG, "GoogleApiClient connection failed: " + connectionResult.toString());
if (!connectionResult.hasResolution()) {
// show the localized error dialog.
GoogleApiAvailability.getInstance().getErrorDialog(this, connectionResult.getErrorCode(), 0).show();
return;
}
// The failure has a resolution. Resolve it.
// Called typically when the app is not yet authorized, and an
// authorization
// dialog is displayed to the user.
try {
connectionResult.startResolutionForResult(this, REQUEST_CODE_RESOLUTION);
} catch (IntentSender.SendIntentException e) {
Log.e(TAG, "Exception while starting resolution activity", e);
}
}
/ENDE CODE/
Gradle:
apply plugin: 'com.android.application'
android {
dexOptions {
incremental true
javaMaxHeapSize "2048M"
}
compileSdkVersion 23
buildToolsVersion '23.0.2'
defaultConfig {
multiDexEnabled true
applicationId "com.woundcentrics.abxsteward"
minSdkVersion 14
targetSdkVersion 21
versionCode 1
versionName "0.4 (Beta)"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/LICENSE'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/DEPENDENCIES'
}
productFlavors {
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'org.robolectric:robolectric:3.0'
compile project(':openCVLibrary310')
compile files('libs/itextpdf-5.1.0.jar')
compile project(':scanlibrary')
apply plugin: 'com.google.gms.google-services'
compile 'me.dm7.barcodescanner:zbar:1.8.3'
compile 'com.mcxiaoke.volley:library-aar:1.0.0'
compile 'com.google.code.gson:gson:2.4'
compile 'com.android.support:appcompat-v7:23.0.0'
compile 'com.google.android.gms:play-services:8.3.0'
compile 'com.google.android.gms:play-services-ads:8.3.0'
compile 'com.google.android.gms:play-services-identity:8.3.0'
compile 'com.google.android.gms:play-services-gcm:8.3.0'
}
repositories {
jcenter()
}
Logcat Nachricht:
GoogleApiClient connection failed: ConnectionResult{statusCode=SIGN_IN_REQUIRED, resolution=PendingIntent{21d08740: [email protected]}, message=null}
Warum und wo wird die Datei 'client_id.json' während eines Builds gepackt? – mDroidd
Danke das ist, was ich gesucht habe –