Closed raiarainne closed 5 years ago
Thanks for the report. Can you link the sample code you tried?
===== Activity Class=====
/* SignIn function is called when this activity is created*/
private void signIn() {
Log.i(TAG, "Start sign in");
GoogleSignInClient GoogleSignInClient = buildGoogleSignInClient();
startActivityForResult(GoogleSignInClient.getSignInIntent(), REQUEST_CODE_SIGN_IN);
}
/** Build a Google SignIn client. */
private GoogleSignInClient buildGoogleSignInClient() {
GoogleSignInOptions signInOptions =
new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestScopes(Drive.SCOPE_FILE)
.build();
return GoogleSignIn.getClient(this, signInOptions);
}
/** Create a new file and save it to Drive. */
private void saveFileToDrive() {
File pdfFile = new File(Environment.getExternalStorageDirectory() + "/FARM REPORT PDF DOWNLOAD/" + Constants.reportfrom+".pdf");
mDriveResourceClient
.createContents()
.continueWithTask(
task -> createFileIntentSender(task.getResult(), pdfFile))
.addOnFailureListener(
e -> Log.w(TAG, "Failed to create new contents.", e));
}
/**
* Creates an {@link IntentSender} to start a dialog activity with configured {@link
* CreateFileActivityOptions} for user to create a new photo in Drive.
*/
private Task<Void> createFileIntentSender(DriveContents driveContents, File file) {
Log.i(TAG, "New contents created.");
// Get an output stream for the contents.
OutputStream outputStream = driveContents.getOutputStream();
try {
FileInputStream fileInputStream = new FileInputStream(file);
byte[] buffer = new byte[1024];
int bytesRead;
while ((bytesRead = fileInputStream.read(buffer)) != -1) {
outputStream.write(buffer, 0, bytesRead);
}
} catch (IOException e1) {
Log.i(TAG, "U AR A MORON! 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("Android Photo.pdf")
.build();
// Set up options to configure and display the create file activity.
CreateFileActivityOptions createFileActivityOptions =
new CreateFileActivityOptions.Builder()
.setInitialMetadata(metadataChangeSet)
.setInitialDriveContents(driveContents)
.build();
return mDriveClient
.newCreateFileActivityIntentSender(createFileActivityOptions)
.continueWith(
task -> {
startIntentSenderForResult(task.getResult(), REQUEST_CODE_CREATOR, null, 0, 0, 0);
return null;
});
}
@Override
protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case REQUEST_CODE_SIGN_IN:
Log.i(TAG, "Sign in request code");
// Called after user is signed in.
if (resultCode == RESULT_OK) {
Log.i(TAG, "Signed in successfully.");
// Use the last signed in account here since it already have a Drive scope.
mDriveClient = Drive.getDriveClient(this, GoogleSignIn.getLastSignedInAccount(this));
// Build a drive resource client.
mDriveResourceClient =
Drive.getDriveResourceClient(this, GoogleSignIn.getLastSignedInAccount(this));
saveFileToDrive();
}
break;
case REQUEST_CODE_CREATOR:
Log.i(TAG, "creator request code");
// Called after a file is saved to Drive.
if (resultCode == RESULT_OK) {
Log.i(TAG, "file successfully saved.");
}
break;
}
}
========== build.gradle==========
compile 'com.google.android.gms:play-services-drive:11.6.0'
compile 'com.google.android.gms:play-services-auth:11.6.0'
compileSdkVersion 26
buildToolsVersion '26.0.2'
Having some issue with text files..
Closing due to inactivity.
I have tried to upload image on my google drive with this sample code I can see the uploaded file when i open google drive explore in my sample app But If i open my google drive on my PC, i can't see the files which i uploaded in my sample app Please give me a solution how i can see the uploaded files
Also i have build app on my Another device And then, i have opened the Google Drive Explore in the sample app. I can't see the saved images which i could see on previous device