Created
July 16, 2015 22:12
-
-
Save Budincsevity/0f62182f1e66e611129f to your computer and use it in GitHub Desktop.
InApp Billing on Android
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
final String id = "android.test.purchased"; | |
mConnection = new ServiceConnection() { | |
@Override | |
public void onServiceConnected(ComponentName name, IBinder binder) { | |
service = IInAppBillingService.Stub.asInterface(binder); | |
String purchaseToken = "inapp:" + getPackageName() + ":android.test.purchased"; | |
try { | |
int response = service.consumePurchase(3, getPackageName(), purchaseToken); | |
} catch (RemoteException e) { | |
e.printStackTrace(); | |
} | |
Bundle buyIntentBundle = null; | |
try { | |
buyIntentBundle = service.getBuyIntent(3, getPackageName(), | |
id, "inapp", randomUUID().toString()); | |
} catch (RemoteException e) { | |
e.printStackTrace(); | |
} | |
if (buyIntentBundle != null) { | |
PendingIntent pendingIntent = buyIntentBundle.getParcelable("BUY_INTENT"); | |
try { | |
startIntentSenderForResult(pendingIntent.getIntentSender(), | |
1001, new Intent(), Integer.valueOf(0), Integer.valueOf(0), | |
Integer.valueOf(0)); | |
} catch (IntentSender.SendIntentException e) { | |
e.printStackTrace(); | |
} | |
} | |
} | |
@Override | |
public void onServiceDisconnected(ComponentName name) { | |
service = null; | |
} | |
}; | |
Intent serviceIntent = new Intent("com.android.vending.billing.InAppBillingService.BIND"); | |
serviceIntent.setPackage("com.android.vending"); | |
bindService(serviceIntent, | |
mConnection, Context.BIND_AUTO_CREATE); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment