android - DOMException:支付应用程序返回了 RESULT_CANCELED 代码。这就是支付应用程序以编程方式关闭其活动的方式
问题描述
问题
我正在尝试使用此Google Tutorial在 TWA 上实施 Google Play Billing ,但是当我调用const paymentResponse = await request.show();
时会发生以下错误:
DOMException: Payment app returned RESULT_CANCELED code. This is how payment apps can close their activity programmatically.
代码
这是我从 JS 端在 TWA 应用程序上运行的代码:
const service =
await window.getDigitalGoodsService('https://play.google.com/billing');
const skuDetails = await service.getDetails(['gem']);
let paymentMethods = [{
supportedMethods: "https://play.google.com/billing",
data: {
sku: skuDetails[0],
}
}];
let paymentDetails = {
total: {
label: `Total`,
amount: {currency: `USD`, value: `10`}
}
};
const request = new PaymentRequest(paymentMethods, paymentDetails);
const paymentResponse = await request.show();
我没有使用Bubblewrap
,而是使用 Android Studio 来完全控制应用程序。
这是我的安卓清单:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mwar.maliciouswar">
<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/Theme.MaliciousWar">
<meta-data
android:name="asset_statements"
android:resource="@string/asset_statements" />
<activity
android:name="com.google.androidbrowserhelper.trusted.LauncherActivity">
<!-- Edit android:value to change the url opened by the Trusted Web Activity -->
<meta-data
android:name="android.support.customtabs.trusted.DEFAULT_URL"
android:value="https://mal-war.com?utm_source=twa" />
<meta-data
android:name="android.support.customtabs.trusted.STATUS_BAR_COLOR"
android:resource="@color/brown"/>
<meta-data
android:name="android.support.customtabs.trusted.STATUS_BAR_COLOR_DARK"
android:resource="@color/brown" />
<meta-data
android:name="android.support.customtabs.trusted.NAVIGATION_BAR_COLOR"
android:resource="@color/brown" />
<meta-data
android:name="android.support.customtabs.trusted.NAVIGATION_BAR_COLOR_DARK"
android:resource="@color/brown" />
<meta-data android:name="android.support.customtabs.trusted.DISPLAY_MODE"
android:value="immersive"/>
<meta-data android:name="android.support.customtabs.trusted.SCREEN_ORIENTATION"
android:value="landscape"/>
<!-- <meta-data android:name="android.support.customtabs.trusted.SPLASH_IMAGE_DRAWABLE"-->
<!-- android:resource="@drawable/splash"/>-->
<!-- <meta-data android:name="android.support.customtabs.trusted.SPLASH_SCREEN_BACKGROUND_COLOR"-->
<!-- android:resource="@color/backgroundColor"/>-->
<!-- <meta-data android:name="android.support.customtabs.trusted.SPLASH_SCREEN_FADE_OUT_DURATION"-->
<!-- android:value="300"/>-->
<!-- <meta-data android:name="android.support.customtabs.trusted.FILE_PROVIDER_AUTHORITY"-->
<!-- android:value="@string/provider_authority"/>-->
<!-- This intent-filter adds the Trusted Web Activity to the Android Launcher -->
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<!--
This intent-filter allows the Trusted Web Activity to handle Intents to open
airhorner.com.
-->
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE"/>
<!-- Edit android:host to handle links to the target URL-->
<data
android:scheme="https"
android:host="mal-war.com"/>
</intent-filter>
</activity>
<activity android:name="com.google.androidbrowserhelper.trusted.FocusActivity" />
<!-- <provider-->
<!-- android:name="androidx.core.content.FileProvider"-->
<!-- android:authorities="com.example.twa.myapplication.fileprovider"-->
<!-- android:grantUriPermissions="true"-->
<!-- android:exported="false">-->
<!-- <meta-data-->
<!-- android:name="android.support.FILE_PROVIDER_PATHS"-->
<!-- android:resource="@xml/filepaths" />-->
<!-- </provider>-->
<service
android:name=".ExtraFeaturesService"
android:exported="true">
<intent-filter>
<action android:name="android.support.customtabs.trusted.TRUSTED_WEB_ACTIVITY_SERVICE"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</service>
<activity
android:name="com.google.androidbrowserhelper.playbilling.provider.PaymentActivity"
android:theme="@android:style/Theme.Translucent.NoTitleBar"
android:configChanges="keyboardHidden|keyboard|orientation|screenLayout|screenSize"
android:exported="true">
<intent-filter>
<action android:name="org.chromium.intent.action.PAY" />
</intent-filter>
<meta-data
android:name="org.chromium.default_payment_method_name"
android:value="https://play.google.com/billing" />
</activity>
<!-- This service checks who calls it at runtime. -->
<service
android:name="com.google.androidbrowserhelper.playbilling.provider.PaymentService"
android:exported="true" >
<intent-filter>
<action android:name="org.chromium.intent.action.IS_READY_TO_PAY" />
</intent-filter>
</service>
</application>
</manifest>
和我的 build.gradle
plugins {
id 'com.android.application'
}
android {
compileSdkVersion 30
buildToolsVersion "30.0.3"
defaultConfig {
applicationId "com.mwar.maliciouswar"
minSdkVersion 23 // android 6.0
targetSdkVersion 30
versionCode 9
versionName "1.06"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.3.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
implementation 'com.google.androidbrowserhelper:androidbrowserhelper:2.2.2'
// implementation "com.android.billingclient:billing:4.0.0"
implementation 'com.google.androidbrowserhelper:billing:1.0.0-alpha08'
}
解决方案
推荐阅读
- r - 每次事件出现在R中的数据帧上时如何计算前值和后值
- maven - 如何在不使用 Maven 的情况下将 JAXB 与 Java 11 一起使用
- types - 存储长数字串的最佳数据结构
- delphi - 如何在运行时完全加载报表 FastReports?
- c++ - 如何通过 CTOR 在 constexpr 中从 STRING LITERAL 初始化 char 数组成员
- android - 在视图模型不起作用的片段之间更改
- vb.net - 加载表单时如何避免图片框中的礼物很少冻结
- javascript - 如何使用 Discord 机器人嵌入消息?
- kotlin - Project Reactor 的 flatMap 运算符中的背压如何工作?
- typescript - 在 TypeScript 中获取类名作为类型