티스토리 뷰
728x90
지난 포스팅에서는 Google Drive 연동을 위한 설정에 대해 다뤘다.
이번에는 실제 샘플을 이용해서 Google Drive 연동이 정상 동작 하는지 확인해보자.
[Android] - Google Drive REST API v3 for Android (1)
Google sample project
◼ Github 주소
https://github.com/gsuitedevs/android-samples/tree/master/drive/deprecation
◼ Menifest
하단 package 명과 OAuth 클라이언트 ID 의 패키지 이름과 일치해야 한다.
(참고로, sample project 에는 gradle 의 applicationId 를 사용하지 않아 menifest 의 package 를 참조한다.)
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
<?xml version="1.0" encoding="utf-8"?> | |
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | |
package="com.google.android.gms.drive.sample.driveapimigration"> | |
<!-- Permissions required by GoogleAuthUtil --> | |
<uses-permission android:name="android.permission.GET_ACCOUNTS" /> | |
<uses-permission android:name="android.permission.MANAGE_ACCOUNTS" /> | |
<uses-permission android:name="android.permission.INTERNET" /> | |
<application | |
android:allowBackup="true" | |
android:icon="@mipmap/ic_launcher" | |
android:label="@string/app_name" | |
android:roundIcon="@mipmap/ic_launcher_round" | |
android:supportsRtl="true" | |
android:theme="@style/AppTheme"> | |
<activity | |
android:name=".MainActivity" | |
android:exported="true"> | |
<intent-filter> | |
<action android:name="android.intent.action.MAIN"/> | |
<category android:name="android.intent.category.LAUNCHER"/> | |
</intent-filter> | |
</activity> | |
</application> | |
</manifest> |
Sample app 실행
앱을 실행하면 하단과 같이 계정을 선택하라는 창이 뜬다.
계정 연동이 완료되면 open 을 click 하여 Google Drive 에 접근한다.
하단과 같이 정상적으로 항목이 나옴을 확인한다.
Login error
여기까지 했는데 login 이 안될 경우는 아래와 같이 error 값을 확인할 수 있다.
◼ MainActivity
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
@Override | |
public void onActivityResult(int requestCode, int resultCode, Intent resultData) { | |
GoogleSignIn.getSignedInAccountFromIntent(resultData) | |
.addOnSuccessListener(new OnSuccessListener<GoogleSignInAccount>() { | |
@Override | |
public void onSuccess(GoogleSignInAccount googleSignInAccount) { | |
Log.i(TAG, "Signed in as " + googleSignInAccount.getEmail()); | |
} | |
}) | |
.addOnFailureListener(new OnFailureListener() { | |
@Override | |
public void onFailure(@NonNull Exception e) { | |
Log.e(TAG, "Unable to sign in!", e); | |
} | |
}); | |
switch (requestCode) { | |
case REQUEST_CODE_SIGN_IN: | |
if (resultCode == Activity.RESULT_OK && resultData != null) { | |
handleSignInResult(resultData); | |
} | |
break; | |
case REQUEST_CODE_OPEN_DOCUMENT: | |
if (resultCode == Activity.RESULT_OK && resultData != null) { | |
Uri uri = resultData.getData(); | |
if (uri != null) { | |
openFileFromFilePicker(uri); | |
} | |
} | |
break; | |
} | |
super.onActivityResult(requestCode, resultCode, resultData); | |
} |
728x90
'Android' 카테고리의 다른 글
Multidex 적용하기 (0) | 2020.01.14 |
---|---|
dp, dip, sp, px (0) | 2020.01.09 |
Android studio 로 SHA1 key 쉽게 알아내기 (0) | 2019.12.02 |
Google Drive REST API v3 for Android (1) (0) | 2019.11.27 |
안드로이드 스튜디오 라이브러리 프로젝트(모듈) link 시키기 (0) | 2019.06.17 |
댓글
250x250
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
TAG
- StartService
- task
- 리워드앱
- task 생성
- 앱테크 추천
- 무료채굴
- android intent
- android task
- WEMIX
- mPANDO
- notifyDataSetChanged
- android flag activity
- 안드로이드 서비스
- Android Service
- 채굴앱
- android activity flag
- M2E
- onContextItemSelected
- 안드로이드 인텐트
- 무료 채굴
- StringUtils
- onCreateContextMenu
- 앱테크
- bindservice
- 리워드 어플
- RoomDatabase
- BroadcastReceiver
- p2e
- Intent
- registerForContextMenu
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
글 보관함