设置 Google Pay API
如果您还没有 Android Studio,请下载并安装 Android Studio。
添加依赖项
Google Pay API 是 Google Play 服务的一部分,因此您只需要导入 Google Play 服务库即可取得所有需要的组件。或者,您也可以选择您想自行编译的 API。
要导入整个 Google Play 服务库,请参阅设置 Google Play 服务。
如果您仅希望选择性地编译您需要的 API,请打开应用模块中的 build.gradle
文件,并将以下内容添加到依赖项区块中:
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,您需要将以下 Google Pay API 元数据元素添加到项目的 AndroidManifest.xml
文件的 <application>
元素中。
<meta-data
android:name="com.google.android.gms.wallet.api.enabled"
android:value="true" />
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2024-10-16。
[null,null,["最后更新时间 (UTC):2024-10-16。"],[[["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"]]