我想要求用户在应用内购买之前选择谷歌帐户?
如果可能的话,有人可以帮助我使其成为可能吗?
在启动应用内购买之前,我正在使用此功能:
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")
}"
集成 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());
}
}