我正在使用“结算”整个系统,但是完成购买后我无法获得购买令牌和DeveloperPayload,每次尝试时,都会获得ThePurchaseToken和DeveloperPayLoad空值
我尝试过
Purchase purchase;
ConsumeParams consumeparams;
purchase.getPurchaseToken();
purchase.getDeveloperPayload();
consumeparams.getPurchaseToken();
consumeparams.getDeveloperPayload();
所有onOnPurchasesUpdated
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_poner_dinero);
LocalBroadcastManager.getInstance(this).registerReceiver(mMessageReceiver,
new IntentFilter("custom-message"));
loadProduct.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (billingClient.isReady())
{
SkuDetailsParams params = SkuDetailsParams.newBuilder()
.setSkusList(Arrays.asList("a" , "b" , "c" , "d" , "3" , "e", "f", "g", "h", "i", "j", "k"))
.setType(BillingClient.SkuType.INAPP)
.build();
billingClient.querySkuDetailsAsync(params, new SkuDetailsResponseListener() {
@Override
public void onSkuDetailsResponse(BillingResult responseCode, List<SkuDetails> skuDetailsList) {
if (responseCode.getResponseCode() == BillingClient.BillingResponseCode.OK)
{
loadProductToRecyclerView(skuDetailsList);
}
else
{
Toast.makeText(ponerDineroActivity.this, "not found", Toast.LENGTH_SHORT).show();
}
}
});
}
else
{
Toast.makeText(ponerDineroActivity.this, "Try again", Toast.LENGTH_SHORT).show();
}
}
});
setupBillingClient();
}
public BroadcastReceiver mMessageReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
// Get extra data included in the Intent
String ItemName = intent.getStringExtra("item");
Toast.makeText(ponerDineroActivity.this, ItemName ,Toast.LENGTH_SHORT).show();
ultimacompra.setText(ItemName);
}
};
private void setupBillingClient() {
billingClient = BillingClient.newBuilder (this).setListener(this).enablePendingPurchases().build();
billingClient.startConnection(new BillingClientStateListener() {
@Override
public void onBillingSetupFinished(BillingResult responseCode) {
if (responseCode.getResponseCode() == BillingClient.BillingResponseCode.OK)
{
Toast.makeText(ponerDineroActivity.this, "works", Toast.LENGTH_SHORT).show();
}
else
{
Toast.makeText(ponerDineroActivity.this, "works denied", Toast.LENGTH_SHORT).show();
}
}
@Override
public void onBillingServiceDisconnected() {
Toast.makeText(ponerDineroActivity.this, "Disconnected", Toast.LENGTH_SHORT).show();
}
});
}
private void loadProductToRecyclerView(List<SkuDetails> skuDetailsList) {
MyProductAdapter adapter = new MyProductAdapter(ponerDineroActivity.this, skuDetailsList,billingClient);
recyclerProduct.setAdapter(adapter);
}
@Override
public void onPurchasesUpdated(BillingResult responseCode, @Nullable List<Purchase> purchases) {
Toast.LENGTH_SHORT).show();
if (responseCode.getResponseCode() == BillingClient.BillingResponseCode.OK)
{
String wml = purchase.getPurchaseToken();
String fit = conssumeparams.getDeveloperPayload();
final ConsumeParams consumeParams =
ConsumeParams.newBuilder()
.setPurchaseToken(wml)
.setDeveloperPayload(fit)
.build();
new ConsumeResponseListener() {
@Override
public void onConsumeResponse(BillingResult billingResult, String outToken) {
if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK) {
if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK)
{
currentusermoneyFB = FirebaseDatabase.getInstance().getReference().child("Usuarios").child(currentuserid);
currentusermoneyFB.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
String currentusermoneyextra = (String) dataSnapshot.child("Dinero").getValue();
itemName = ultimacompra.getText().toString();
myNum = Integer.parseInt(itemName);
myNum2 = Integer.parseInt(currentusermoneyextra);
int total = myNum + myNum2;
String strI = String.valueOf(total);
DatabaseReference ref = FirebaseDatabase.getInstance().getReference().child("Usuarios");
HashMap<String, Object> userMap = new HashMap<>();
userMap.put("Dinero", strI);
ref.child(Prevalent.currentOnlineUser.getTelefono()).updateChildren(userMap);
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
}
else
{
Toast.makeText(ponerDineroActivity.this, "ERROR", Toast.LENGTH_SHORT).show();
}
}
else
{
Toast.makeText(ponerDineroActivity.this, "Try again", Toast.LENGTH_SHORT).show();
}
billingClient.consumeAsync(consumeParams, listener);
}
};
}
else
{
Toast.makeText(this, "ERROR", Toast.LENGTH_SHORT).show();
}
}
}
我需要从购买的商品中获取DeveloperPayload和getPurchaseToken才能消费该产品
我一直在指导自己阅读文档:
https://developer.android.com/google/play/billing/billing_onetime
有什么主意吗?谢谢