This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Button( | |
onClick = { | |
startForResult.launch(getGoogleSignInClient(ctx).signInIntent) | |
}, | |
modifier = Modifier() | |
) { | |
Text(text = "Sign in with Google") | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun getGoogleSignInClient(context: Context): GoogleSignInClient { | |
val signInOptions = GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) | |
.requestEmail() | |
.requestScopes(Scope(DriveScopes.DRIVE_FILE), Scope(DriveScopes.DRIVE)) | |
.build() | |
return GoogleSignIn.getClient(context, signInOptions) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
GoogleSignIn.getLastSignedInAccount(context)?.let { googleAccount -> | |
// get credentials | |
val credential = GoogleAccountCredential.usingOAuth2( | |
context, listOf(DriveScopes.DRIVE, DriveScopes.DRIVE_FILE) | |
) | |
credential.selectedAccount = googleAccount.account!! | |
// get Drive Instance | |
val drive = Drive |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
viewModelScope.launch(Dispatchers.IO) { | |
// Define a Folder | |
val gFolder = com.google.api.services.drive.model.File() | |
// Set file name and MIME | |
gFolder.name = "My Cool Folder Name" | |
gFolder.mimeType = "application/vnd.google-apps.folder" | |
// You can also specify where to create the new Google folder | |
// passing a parent Folder Id | |
val parents: MutableList<String> = ArrayList(1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for (file in files) { | |
val gfile = com.google.api.services.drive.model.File() | |
val fileContent = FileContent("your_mime", file) | |
gfile.name = file.name | |
val parents: MutableList<String> = ArrayList(1) | |
parents.add("folder_id") // Here you need to get the parent folder id | |
gfile.parents = parents |
OlderNewer