在 Android 上进行应用内购买之前我可以选择我的 Google 帐户吗?

问题描述 投票:0回答:2

我想要求用户在应用内购买之前选择谷歌帐户?

如果可能的话,有人可以帮助我使其成为可能吗?

在启动应用内购买之前,我正在使用此功能:

fun startPurchaseFlow(productType: String, listOfProducts: Array<ProductDetails>) {

val product = listOfProducts.find { it.productId == productType }
product?.let {
val productDetailsParams = mutableListOf(
ProductDetailsParams.newBuilder()
.setProductDetails(it)
.setOfferToken(it.subscriptionOfferDetails?.get(0)!!.offerToken)
.build()
)
val billingFlowParams = BillingFlowParams.newBuilder()
.setProductDetailsParamsList(productDetailsParams).build()
billingClient.launchBillingFlow(context as Activity, billingFlowParams)
} ?: inAppPurchaseListener?.onErrorLaunchBilling("Product not found: $productType")
}"
java android kotlin in-app-purchase in-app-billing
2个回答
-1
投票

集成 Google 登录

尝试下面的代码:

private static final int RC_SIGN_IN = 9001;

// Inside your Activity
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
        .requestEmail()
        .build();

GoogleSignInClient mGoogleSignInClient = GoogleSignIn.getClient(this, gso);

// Sign-in intent
private void signIn() {
    Intent signInIntent = mGoogleSignInClient.getSignInIntent();
    startActivityForResult(signInIntent, RC_SIGN_IN);
}

// Handling sign-in result
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    // Result returned from launching the Intent from GoogleSignInClient.getSignInIntent(...);
    if (requestCode == RC_SIGN_IN) {
        Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
        handleSignInResult(task);
    }
}

private void handleSignInResult(Task<GoogleSignInAccount> completedTask) {
    try {
        GoogleSignInAccount account = completedTask.getResult(ApiException.class);

        // Signed in successfully, show authenticated UI or proceed with the purchase.
    } catch (ApiException e) {
        // The ApiException status code indicates the detailed failure reason.
        Log.w(TAG, "signInResult:failed code=" + e.getStatusCode());
    }
}

-1
投票

您可以使用谷歌要求您的用户登录您的应用程序,并向您提供帐户信息 例如(姓名、电子邮件、图片)等。 您也可以使用 google Api 让用户登录或使用 firebase 来实现此目的

这是链接

这里

© www.soinside.com 2019 - 2024. All rights reserved.