Upgrade to Pro — share decks privately, control downloads, hide ads and more …

[DroidKaigi 2017] Function Introduction of Google Play Services

syarihu
March 08, 2017

[DroidKaigi 2017] Function Introduction of Google Play Services

「Function Introduction of Google Play Services」の発表資料です。

syarihu

March 08, 2017
Tweet

More Decks by syarihu

Other Decks in Programming

Transcript

  1. Taichi Sato (@syarihu) • GMO Media, inc. • エンジニア ◦

    Androidアプリ ◦ サーバーサイドアプリ (Java)
  2. 以前のGoogle Sign-In • AuthTokenの取得 ( AccountManager#getAuthToken ) ◦ 認証状態の確認 ◦

    認証されてなかったら認証許可ダイアログを表示 ◦ 認証されてたらAuthTokenを取得 ◦ 認証許可が外れてたら再取得も自分で…
  3. 以前のGoogle Sign-In • アカウントの選択でつかうメソッド AccountManager.newChooseAccountIntent( Account selectedAccount, ArrayList<Account> allowableAccounts, String[]

    allowableAccountTypes, boolean alwaysPromptForAccount, String descriptionOverrideText, String addAccountAuthTokenType, String[] addAccountRequiredFeatures, Bundle addAccountOptions)
  4. Google Sign-Inを使うための前提条件 • Google Play Storeを含むAndroid 2.3以上 • または、Android 4.2.2以降のGoogle

    API プラットフォームを実行する、Google Play Servicesのバージョン9.8.0以降を含むAVD
  5. Google Sign-In APIの実装 • GoogleSignInOptions オブジェクトを作成 • GoogleApiClient オブジェクトを作成 •

    Google サインインボタンを追加する • サインイン処理の実装 • サインアウト処理の実装
  6. mGoogleApiClient = new GoogleApiClient.Builder(this) .enableAutoManage( this /* FragmentActivity */, this

    /* OnConnectionFailedListener */) .addApi(Auth.GOOGLE_SIGN_IN_API, gso) .build(); mGoogleApiClient.connect();  GoogleApiClient オブジェクトを作成
  7. @Override public void onActivityResult( int requestCode,int resultCode, Intent data) {

    super.onActivityResult(requestCode, resultCode, data); /** GoogleSignInResult */ }  サインイン処理の実装
  8. private void handleSignInResult( GoogleSignInResult result) { if (result.isSuccess()) { mGoogleSignInAccount

    = result .getSignInAccount(); showMessage(result.getSignInAccount() .getEmail()); } }  サインイン処理の実装
  9. private void handleSignInResult( GoogleSignInResult result) { if (result.isSuccess()) { mGoogleSignInAccount

    = result .getSignInAccount(); showMessage(result.getSignInAccount() .getEmail()); } }  サインイン処理の実装
  10. private void handleSignInResult( GoogleSignInResult result) { if (result.isSuccess()) { mGoogleSignInAccount

    = result .getSignInAccount(); showMessage(result.getSignInAccount() .getEmail()); } }  サインイン処理の実装
  11. new ResultCallback<Status>() { @Override public void onResult(Status status) { //

    サインアウト後の処理 } });  サインアウト処理の実装
  12. Firebase Dynamic Linksの有効化 • そのため、Firebase Dynamic Linksを有効 にしていない場合は、Firebase Consoleから [Dynamic

    Links] セクションを開き、表示され る利用規約に同意して、有効にする
  13.  ディープリンク用のActivityを作成 public class AppInvitesActivity extends AppCompatActivity { @Override protected void

    onStart() { super.onStart(); Intent intent = getIntent(); // IntentにApp Invitesの情報が含まれているか調べる if (AppInviteReferral.hasReferral(intent)) { processReferralIntent(intent); } }
  14.  ディープリンク用のActivityを作成 public class AppInvitesActivity extends AppCompatActivity { @Override protected void

    onStart() { super.onStart(); Intent intent = getIntent(); // IntentにApp Invitesの情報が含まれているか調べる if (AppInviteReferral.hasReferral(intent)) { processReferralIntent(intent); } }
  15.  ディープリンク用のActivityを作成 private void processReferralIntent(Intent intent) { // 招待ID取得 String invitationId

    = AppInviteReferral.getInvitationId(intent); // ディープリンク用URL取得 String deepLink = AppInviteReferral.getDeepLink(intent); // ディープリンクのURLに含まれるパラメータを使って // 何か処理したりする
  16. mGoogleApiClient = new GoogleApiClient.Builder(this) .enableAutoManage( this /* FragmentActivity */, this

    /* OnConnectionFailedListener */) .addApi(Auth.GOOGLE_SIGN_IN_API, gso) .build(); mGoogleApiClient.connect();  App Invitesを受け入れる
  17. new ResultCallback<AppInviteInvitationResult>() { @Override public void onResult( AppInviteInvitationResult result) {

    // ここに自分でディープリンクを受け取って // Activityを起動する処理を書く } });  App Invitesを受け入れる
  18. Google Analyticsの設定 • 管理 -> プロパティ -> カスタム定義 -> カスタ

    ムディメンション -> 新しいカスタムディメンション から、ディメンションを追加する