我在我的应用程序中使用谷歌驱动器授权。当我使用android studio debug / run选项运行应用程序时,它运行正常。但是,今天我发布了应用程序,安装后,我被困在choose account for appname
。我不知道发生了什么错误?
我尝试了几个选项:
由于在将apk上传到Google Play商店时,应用包名称不应包含.example,因此我在https://console.developers.google.com/
凭据中执行了相同的操作。这没有用。
尝试重新安装该应用程序,但它也没有用。
谷歌驱动器代码是:
private void saveFileToDrive() {
// Start by creating a new contents, and setting a callback.
//Log.i(TAG, "Creating new contents.");
Drive.DriveApi.newDriveContents(mGoogleApiClient)
.setResultCallback(new ResultCallback<DriveContentsResult>() {
@Override
public void onResult(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.
FileInputStream fis;
try {
fis = new FileInputStream(outputFile);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] buf = new byte[1024];
int n;
while (-1 != (n = fis.read(buf)))
baos.write(buf, 0, n);
byte[] photoBytes = baos.toByteArray();
outputStream.write(photoBytes);
outputStream.close();
fis.close();
//Log.w(TAG, "Successfully written: ");
// let us delete the file here
File file = new File(outputFile);
if (file.delete())
{
//Log.d(TAG, "Successfully deleted.");
}
} catch (FileNotFoundException e) {
//Log.w(TAG, "FileNotFoundException: " + e.getMessage());
} catch (IOException e1) {
//Log.w(TAG, "Unable to write file contents." + e1.getMessage());
}
// 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("audio/mpeg").setTitle(file_name_with_extension).build();
// Create an intent for the file chooser, and start it.
Drive.DriveApi.getRootFolder(mGoogleApiClient)
.createFile(mGoogleApiClient, metadataChangeSet, result.getDriveContents())
;
}
});
}
/**
* Called before the activity is destroyed
*/
@Override
public void onDestroy() {
if (mAdView != null) {
mAdView.destroy();
}
super.onDestroy();
}
@Override
protected void onResume() {
super.onResume();
if (mAdView != null) {
mAdView.resume();
}
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 (mAdView != null) {
mAdView.pause();
}
if (mGoogleApiClient != null) {
mGoogleApiClient.disconnect();
}
super.onPause();
}
@Override
protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
if (resultCode == Activity.RESULT_OK) {
// Store the image data as a bitmap for writing later.
//Log.d(TAG, "Data is saved successfully.");
Toast.makeText(getApplicationContext(), "The file " + file_name + " has been saved successfully to your drive.", Toast.LENGTH_LONG).show();
}
}
@Override
public void onConnectionFailed(ConnectionResult result) {
// Called whenever the API client fails to connect.
//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;
}
// 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 {
result.startResolutionForResult(this, REQUEST_CODE_RESOLUTION);
} catch (SendIntentException e) {
//Log.e(TAG, "Exception while starting resolution activity", e);
}
}
@Override
public void onConnected(Bundle connectionHint) {
//Log.i(TAG, "API client connected.");
}
@Override
public void onConnectionSuspended(int cause) {
//Log.i(TAG, "GoogleApiClient connection suspended");
}
我的应用程序就在这里:
https://play.google.com/store/apps/details?id=com.khan.spyrecorder
请帮我解决这个问题。