Google Pay API を設定する
前提条件
操作を始める前に、次の前提条件を確認してください。
まだ Android Studio を使用していない場合は、Android Studio をダウンロードしてインストールします。
依存関係を追加する
Google Pay API は Google Play 開発者サービスに含まれています。Google Play 開発者サービス ライブラリをインポートするだけで、必要なものがすべて揃います。あるいは、コンパイルする API を自分で選ぶこともできます。
Google Play 開発者サービス ライブラリ全体をインポートする場合は、Google Play 開発者サービスの設定をご覧ください。
必要な API だけを選択してコンパイルする場合は、アプリ モジュールの build.gradle
ファイルを開き、dependencies ブロックに次の記述を追加します。
dependencies {
implementation 'com.google.android.gms:play-services-wallet:18.1.3'
implementation 'com.android.support:appcompat-v7:24.1.1'
}
上記の各バージョンは、Google Pay API ライブラリの最新バージョンに必要な最小バージョンです。アプリでは上記の値よりも大きな依存関係を選択できます。現在の Google Pay API のバージョン情報については、Google Play 開発者サービスのセットアップをご覧ください。サポート ライブラリの最新情報については、サポート ライブラリの設定をご覧ください。
マニフェストを変更する
アプリで Google Pay を有効にするには、プロジェクトの AndroidManifest.xml
ファイルの <application>
要素に次の Google Pay API meta-data 要素を追加する必要があります。
<meta-data
android:name="com.google.android.gms.wallet.api.enabled"
android:value="true" />
特に記載のない限り、このページのコンテンツはクリエイティブ・コモンズの表示 4.0 ライセンスにより使用許諾されます。コードサンプルは Apache 2.0 ライセンスにより使用許諾されます。詳しくは、Google Developers サイトのポリシーをご覧ください。Java は Oracle および関連会社の登録商標です。
最終更新日 2024-10-16 UTC。
[null,null,["最終更新日 2024-10-16 UTC。"],[[["To use the Google Pay API, your Android app must be distributed through the Google Play Store and built with a `minSdkVersion` of 21 or higher and a `compileSdkVersion` of 34 or higher."],["Before integrating, ensure you have the Google Wallet app installed, add a payment method, and comply with the Google Pay API Acceptable Use Policy and Google Play Developer Policy."],["Implement payments using Google Play In-app Billing if Google processes payments for you or if you sell digital goods."],["Integrate the Google Pay API by adding the necessary dependency to your app's Gradle build file and enabling it in your `AndroidManifest.xml` file."],["To go live, consult the publishing guide for essential information after completing the integration process."]]],["To utilize the Google Pay API, ensure your app is on the Google Play store and meets `minSdkVersion` 21 and `compileSdkVersion` 34 or higher. Install the Google Wallet app with a payment method. If Google processes payments or you sell digital goods, use Google Play In-app Billing. Add the `com.google.android.gms:play-services-wallet:19.4.0` dependency to your module's Gradle file. In your `AndroidManifest.xml`, enable the API with the `meta-data` element: `com.google.android.gms.wallet.api.enabled` with a value of `true`.\n"]]