我正在尝试按照本教程http://blog.blundell-apps.com/simple-inapp-billing-payment/了解应用内购买
到目前为止,这是我的代码:
public class main extends Activity{
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.e("BillingService", "Starting");
setContentView(R.layout.main);
startService(new Intent(this, BillingService.class));
BillingHelper.setCompletedHandler(mTransactionHandler);
}
////////////////////////////////
public Handler mTransactionHandler = new Handler(){
public void handleMessage(android.os.Message msg) {
Log.e("IN APP", "Transaction complete");
Log.e("IN APP", "Transaction status: "+BillingHelper.latestPurchase.purchaseState);
Log.e("IN APP", "Item purchased is: "+BillingHelper.latestPurchase.productId);
if(BillingHelper.latestPurchase.isPurchased())
{
showItem();
}
};
};
////////////////////////////////
public void BuyButtonClick(View v) {
if(BillingHelper.isBillingSupported()){
Log.e("IN APP","Trying to buy...");
BillingHelper.requestPurchase(this, "android.test.purchased");
} else {
Log.e("IN APP","Can't purchase on this device");
}
}
////////////////////////////////////////////////
private void showItem() {
TextView tv1 = (TextView)findViewById(R.id.tv1);
tv1.setText("PAID!");
}
////////////////////////////////////////////////
@Override
protected void onDestroy() {
BillingHelper.stopService();
super.onDestroy();
}
////////////////////////////////
}
一切似乎都很好,但我还想要一些方法来检查应用程序启动时是否购买了该项目。我认为它可能会使用BillingHelper.verifyPurchase(signedData, signature),但是我应该在那里输入什么数据和签名?或者也许还有其他方法?
谢谢!