gpt4 book ai didi

android - 在应用程序计费没有 ui

转载 作者:行者123 更新时间:2023-11-29 02:39:29 25 4
gpt4 key购买 nike

我想学习 App Billing。我创建了一个测试应用程序。我可以使用 getSkuDetails 看到我的应用内产品已插入到 Play Console 中,但是当我启动 launchPurchaseFlow 时,购买应用内产品的界面没有启动,我只能看到日志(Log its ok)

public class MainActivity extends Activity implements View.OnClickListener {

Button compra,click,controllo;
private IabHelper.QueryInventoryFinishedListener mQueryFinishedListener;

IInAppBillingService mService;

ServiceConnection mServiceConn = new ServiceConnection() {
@Override
public void onServiceDisconnected(ComponentName name) {
mService = null;
}

@Override
public void onServiceConnected(ComponentName name,
IBinder service) {
mService = IInAppBillingService.Stub.asInterface(service);
}
};

private static final String TAG="INappBILLING";
IabHelper mHelper;


static final String ITEM_SKU="dsada";
public monky.myapplication.util.IabHelper.OnIabPurchaseFinishedListener
mPurchaseFinishedListener;


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

Intent serviceIntent =
new Intent("com.android.vending.billing.InAppBillingService.BIND");
serviceIntent.setPackage("com.android.vending");
bindService(serviceIntent, mServiceConn, Context.BIND_AUTO_CREATE);

compra=(Button) findViewById(R.id.buybtn);
compra.setOnClickListener(this);
click=(Button)findViewById(R.id.clickbtn);
click.setOnClickListener(this);
controllo=(Button) findViewById(R.id.controllo);
controllo.setOnClickListener(this);



String base64EncodedPublicKey="mykey";

mHelper=new IabHelper(this,base64EncodedPublicKey);

mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
public void onIabSetupFinished(IabResult result) {
if (!result.isSuccess()) {
// Oh no, there was a problem.
Log.d(TAG, "Problem setting up In-app Billing: " + result);
}
// Hooray, IAB is fully set up!
}
});



}





@Override
public void onDestroy() {
super.onDestroy();
if (mService != null) {
unbindService(mServiceConn);
}
}

@Override
public void onClick(View view) {
switch (view.getId()){

case R.id.clickbtn:

List additionalSkuList = new ArrayList();
additionalSkuList.add(ITEM_SKU);
mHelper.queryInventoryAsync(true, additionalSkuList,
mQueryFinishedListener);


mQueryFinishedListener = new IabHelper.QueryInventoryFinishedListener() {
public void onQueryInventoryFinished(IabResult result, Inventory inventory)
{
if (result.isFailure()) {
Log.i(TAG, " - Prezzo Error" );
return;
}


String prezzo = inventory.getSkuDetails(ITEM_SKU).getPrice();

String titolo = inventory.getSkuDetails(ITEM_SKU).getTitle();

String desc = inventory.getSkuDetails(ITEM_SKU).getDescription();

String type = inventory.getSkuDetails(ITEM_SKU).getType();

String SkU = inventory.getSkuDetails(ITEM_SKU).getSku();

Toast.makeText(getApplicationContext(),"Titolo: "+titolo+" Desc "+desc+" Prezzo "+prezzo+" Tipo "+type+"SKU"+SkU ,Toast.LENGTH_LONG).show();
Log.i(TAG, " - Prezzo " + prezzo);

// update the UI
}
};

break;

case R.id.buybtn:
if (!mHelper.isAsyncInProgress()){

mHelper.launchPurchaseFlow(this, ITEM_SKU, 10001,
mPurchaseFinishedListener,"" );
Log.i(TAG, " sono passato " );}
else {
Log.i(TAG, " Non sono passato " );
}



break;


case R.id.controllo:
controlloaq();
break;

}
}

private void controlloaq() {

IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener
= new IabHelper.OnIabPurchaseFinishedListener() {
public void onIabPurchaseFinished(IabResult result, Purchase purchase)
{
if (purchase.getSku().equals(ITEM_SKU)) {
Log.i(TAG, " passato e comprato" );
}

if (result.isFailure()) {
Log.i(TAG, "Error purchasing: " + result);
return;
}



}
};
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);

Log.d(TAG, "onActivityResult(" + requestCode + "," + resultCode + ","
+ data);

// Pass on the activity result to the helper for handling
if (!mHelper.handleActivityResult(requestCode, resultCode, data)) {
super.onActivityResult(requestCode, resultCode, data);
} else {
Log.d(TAG, "onActivityResult handled by IABUtil.");
}
}
}

最佳答案

我认为您的代码几乎是正确的。发生的事情是你的 mPurchaseFinishedListener 没有触发,因为你将它放在一个函数 controlloaq() 中,因此它只会在你调用 controlloaq() 时执行>.

看官方Google In App Billing sample ,你不应该将它包含在一个函数中,除非你知道你在做什么。

// Callback for when a purchase is finished
IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener = new IabHelper.OnIabPurchaseFinishedListener() {
public void onIabPurchaseFinished(IabResult result, Purchase purchase) {
Log.d(TAG, "Purchase finished: " + result + ", purchase: " + purchase);

// if we were disposed of in the meantime, quit.
if (mHelper == null) return;

if (result.isFailure()) {
complain("Error purchasing: " + result);
setWaitScreen(false);
return;
}
if (!verifyDeveloperPayload(purchase)) {
complain("Error purchasing. Authenticity verification failed.");
setWaitScreen(false);
return;
}

Log.d(TAG, "Purchase successful.");

if (purchase.getSku().equals(SKU_GAS)) {
// bought 1/4 tank of gas. So consume it.
Log.d(TAG, "Purchase is gas. Starting gas consumption.");
try {
mHelper.consumeAsync(purchase, mConsumeFinishedListener);
} catch (IabAsyncInProgressException e) {
complain("Error consuming gas. Another async operation in progress.");
setWaitScreen(false);
return;
}
}
else if (purchase.getSku().equals(SKU_PREMIUM)) {
// bought the premium upgrade!
Log.d(TAG, "Purchase is premium upgrade. Congratulating user.");
alert("Thank you for upgrading to premium!");
mIsPremium = true;
updateUi();
setWaitScreen(false);
}
else if (purchase.getSku().equals(SKU_INFINITE_GAS_MONTHLY)
|| purchase.getSku().equals(SKU_INFINITE_GAS_YEARLY)) {
// bought the infinite gas subscription
Log.d(TAG, "Infinite gas subscription purchased.");
alert("Thank you for subscribing to infinite gas!");
mSubscribedToInfiniteGas = true;
mAutoRenewEnabled = purchase.isAutoRenewing();
mInfiniteGasSku = purchase.getSku();
mTank = TANK_MAX;
updateUi();
setWaitScreen(false);
}
}
};

关于android - 在应用程序计费没有 ui,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45244577/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com