Skip to content

Instantly share code, notes, and snippets.

@molidev8
Last active August 16, 2022 16:46
Show Gist options
  • Save molidev8/a9df1f0c4f8f7153972db8a6a294eb60 to your computer and use it in GitHub Desktop.
Save molidev8/a9df1f0c4f8f7153972db8a6a294eb60 to your computer and use it in GitHub Desktop.
Login into the Dropbox user account
fun initDropboxClient() {
val prefs = getSharedPreferences("recipe-vault", MODE_PRIVATE)
val serializedCredential = prefs.getString("credential", null)
if (serializedCredential == null) {
val credential = Auth.getDbxCredential()
if (credential != null) {
prefs.edit().putString("credential", credential.toString()).apply()
dropboxManager.initDropboxClient(credential)
}
}
}
fun DropboxManager.initDropboxClient(credential: DbxCredential) {
val newCredential = DbxCredential(
credential.accessToken,
-1L,
credential.refreshToken,
credential.appKey
)
if (client == null) {
client = DbxClientV2(config, newCredential)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment