There are many ways to upload images and files. Also, there are many places from which to uploads files: Dropbox, local storage on the device, Google Drive and other services. In this tutorial, we are going to take a look at how to upload and create a file in Google Drive. To do so we need to Google Drive SDK and Google Authentication Base on Google Drive Rest API we are going to do that.
Okay, it's enough to talk about it 😎 Let's get into it,
Start a new
Android Studio project from the startup screen or
New Project then select
Empty Activity' from theChoose Project` box.
Enter the name
drive-rest-app company domain and a project location. Make sure to Choose Language Java.
Registering for Google Drive
As we discuss we need to Google Drive SDK, So in order to use it, we need to enable that API. Okay don't worry we will move forward step by step
- Go to Google Console.
- Sign up for a developer account if We don't have or then sign in.
Createa project Or
Selectand click continue from below,
- After creating a project we have
- Now, Select
Libraryon the left-hand side to go to the Search screen
- Type “Google Drive” and select Google Drive API.
- Select Enable. Then It looks like below,
- Back to Dashboard, from Dashboard left-hand side go to Credentials. Create
Credentialby selecting the
OAuth client IDlike below
Tt navigates to the
Create OAuth client ID page. Select our Application Type
- Now we need your
Signing-certificate fingerprintkey. Do so follow below steps
- Copy the keytool text (press the Copy icon) and paste it into a terminal.
- Change the path-to-debug-or-production-keystore to your default debug keystore location:
- On Mac or Linux,
- On Windows,
- After you execute the command, you will be prompted to enter the keystore password. The password for the debug keystore is blank by default, so you can just press Return or Enter.
Notes: If throwing error to generate singing key then it might be
I used an alternative command for my machine
keytool -list -v -keystore ~/.android/debug.keystore -alias androiddebugkey -storepass android -keypass android
If everything works correctly, you should see something like this:
- Copy the
SHA1value from the terminal into the text field and press Create. The Client ID dialog will appear. Press OK.
- Finally, enter a name and the
package namethat we used to
create our app. Although the hint refers to the package name in
AndroidManifest.xml, it has to match the
build.gradleinstead — otherwise, the login flow will fail.
- We don't need to complete the form that appears, it's optional so press
Saveand move on.
Optional, Now, In the Credentials page. Authorization on Android uses the
identify your app, so you
don’t have to downloadany
JSON file or copy any API keyor secret to our project.
It about lots man, Don't worry! Now, we are in the fun part 😎.
Let's Back to the coding part,
Dev.tocan't render source files properly, the rest of the part will cover below.
Top comments (4)
Thanks for this post.
Actually I copied the code that you provided and ran into an issue.
After selecting the gmail account with which I would like to log in the app starts loading but never processes further...
In the logcat:
-I got this messages: E/MemoryLeakMonitorManager: MemoryLeakMonitor.jar is not exist!
-E/Minikin: Could not get cmap table size!
I am just learning Java but I do want/need to learn Google Drive API for my Android app.
Could you pls help me out, if you have any thoughts on this issue?
Sorry for the late response. I'm a little bit overwhelming right now. So you can check out this link below,
I think it's happening because of your android studio version, or API version, or Gradle check that and let me know.
for this github link i have error when i use the filepicker , how to get the fileid while we using filepicker in android studio
Please it's not clear to me. What do you talking about? But if possible explain it briefly.
Add some screen short if possible. I think you are in a trouble to import that project. Please check your android studio version and API version.