Skip to content

Commit c283d02

Browse files
author
hussienalrubaye
committed
in app purchar
1 parent a107560 commit c283d02

File tree

1 file changed

+107
-0
lines changed

1 file changed

+107
-0
lines changed

in app purchase.java

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
//1- requestion permmion
2+
<uses-permission android:name="com.android.vending.BILLING" />
3+
4+
//2- go to men Android SDK Manager -> add Google Play Billing Library .
5+
6+
//3- got o AndroidSDK/extra/google/play_billing/sample
7+
// copy all files in util folder to your app util folder
8+
// add aidl file to your project with name IInAppBillingService.aidl
9+
10+
//4- add product in your play console
11+
12+
//5- add this code to your activity
13+
14+
//***************************Payment***************************
15+
private static final String TAG =
16+
"com.alrubaye.familyfinder";
17+
// test ITEM_SKU android.test.purchased
18+
// test token mypurchasetoken
19+
static final String ITEM_SKU = "com.alrubaye.addmembers";
20+
IabHelper mHelper;
21+
22+
IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener
23+
= new IabHelper.OnIabPurchaseFinishedListener() {
24+
public void onIabPurchaseFinished(IabResult result,
25+
Purchase purchase)
26+
{
27+
if (result.isFailure()) {
28+
// Handle error
29+
return;
30+
}
31+
else if (purchase.getSku().equals(ITEM_SKU)) {
32+
consumeItem();
33+
//clickButton.setEnabled(false);
34+
}
35+
36+
}
37+
};
38+
public void consumeItem() {
39+
mHelper.queryInventoryAsync(mReceivedInventoryListener);
40+
}
41+
42+
IabHelper.QueryInventoryFinishedListener mReceivedInventoryListener
43+
= new IabHelper.QueryInventoryFinishedListener() {
44+
public void onQueryInventoryFinished(IabResult result,
45+
Inventory inventory) {
46+
47+
if (result.isFailure()) {
48+
// Handle failure
49+
} else {
50+
mHelper.consumeAsync(inventory.getPurchase(ITEM_SKU),
51+
mConsumeFinishedListener);
52+
}
53+
}
54+
};
55+
IabHelper.OnConsumeFinishedListener mConsumeFinishedListener =
56+
new IabHelper.OnConsumeFinishedListener() {
57+
public void onConsumeFinished(Purchase purchase,
58+
IabResult result) {
59+
60+
if (result.isSuccess()) {
61+
// clickButton.setEnabled(true);
62+
GlobalClass.AdditionUsers=GlobalClass.AdditionUsers+1;
63+
FileLoad fileLoad=new FileLoad(getApplicationContext());
64+
fileLoad.SaveData();
65+
} else {
66+
// handle error
67+
}
68+
}
69+
};
70+
@Override
71+
protected void onActivityResult(int requestCode, int resultCode,
72+
Intent data)
73+
{
74+
if (!mHelper.handleActivityResult(requestCode,
75+
resultCode, data)) {
76+
super.onActivityResult(requestCode, resultCode, data);
77+
}
78+
}
79+
void PayItem(String ITEM_SKU){
80+
mHelper.launchPurchaseFlow(this, ITEM_SKU, 10001,
81+
mPurchaseFinishedListener, "mypurchasetoken");
82+
}
83+
//***************************************************************
84+
// 7- in oncreate() add this code
85+
//In app purchase
86+
String base64EncodedPublicKey = "your_key"
87+
88+
mHelper = new IabHelper(this, base64EncodedPublicKey);
89+
90+
mHelper.startSetup(new
91+
IabHelper.OnIabSetupFinishedListener() {
92+
public void onIabSetupFinished(IabResult result)
93+
{
94+
if (!result.isSuccess()) {
95+
Log.d(TAG, "In-app Billing setup failed: " + result);
96+
} else {
97+
Log.d(TAG, "In-app Billing is set up OK");
98+
99+
}
100+
}
101+
});
102+
103+
104+
//8- purchuase
105+
PayItem(ITEM_SKU);
106+
107+

0 commit comments

Comments
 (0)