我正在开发应用程序内购买项目:以下是应用程序内购买代码。当我点击“购买物品”按钮谷歌在应用程序购买对话框显示和成功付款后,我得到“付款是成功的”。在应用程序购买中禁用Android中的“购买”按钮活动
现在我想在付款成功时填写“购买物品”按钮当我打开此应用程序时自动禁用。
这里是MainActivity
代码:
public class MainActivity extends Activity {
IInAppBillingService mservice;
ServiceConnection connection;
String inappid = "android.test.purchased"; // replace this with your in-app
// product id
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.purchase);
connection = new ServiceConnection() {
@Override
public void onServiceDisconnected(ComponentName name) {
mservice = null;
}
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
mservice = IInAppBillingService.Stub.asInterface(service);
}
};
bindService(new Intent(
"com.android.vending.billing.InAppBillingService.BIND"),
connection, Context.BIND_AUTO_CREATE);
Button purchaseBtn = (Button) findViewById(R.id.purchase);
purchaseBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
ArrayList skuList = new ArrayList();
skuList.add(inappid);
Bundle querySkus = new Bundle();
querySkus.putStringArrayList("ITEM_ID_LIST", skuList);
Bundle skuDetails;
try {
skuDetails = mservice.getSkuDetails(3, getPackageName(),
"inapp", querySkus);
int response = skuDetails.getInt("RESPONSE_CODE");
if (response == 0) {
ArrayList<String> responseList = skuDetails.getStringArrayList("DETAILS_LIST");
for (String thisResponse : responseList) {
JSONObject object = new JSONObject(thisResponse);
String sku = object.getString("productId");
String price = object.getString("price");
if (sku.equals(inappid)) {
System.out.println("price " + price);
Bundle buyIntentBundle = mservice.getBuyIntent(3, getPackageName(), sku, "inapp", "bGoa+V7g/yqDXvKRqq+JTFn4uQZbPiQJo4pf9RzJ");
PendingIntent pendingIntent = buyIntentBundle.getParcelable("BUY_INTENT");
startIntentSenderForResult(pendingIntent.getIntentSender(), 1001, new Intent(), Integer.valueOf(0), Integer.valueOf(0), Integer.valueOf(0));
}
}
}
}
catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (SendIntentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == 1001) {
String purchaseData = data.getStringExtra("INAPP_PURCHASE_DATA");
if (resultCode == RESULT_OK) {
try {
JSONObject jo = new JSONObject(purchaseData);
String sku = jo.getString(inappid);
Toast.makeText(MainActivity.this, "You have bought the " + sku + ". Excellent choice,adventurer!", Toast.LENGTH_LONG).show();
}
catch (JSONException e) {
System.out.println("Failed to parse purchase data.");
e.printStackTrace();
}
}
}
}
@Override
public void onDestroy() {
super.onDestroy();
if (connection != null) {
unbindService(connection);
}
}
}
谢谢先生的回复。现在,如果我再次打开此应用程序,我会禁用此按钮? –
看到我的编辑禁用后重新打开应用程序 –