Reputation: 63
I keep getting
Null data in IAB activity result
I'm trying to implement in-app billing in my app using Android Trivial example. What am I doing wrong?
public class Donate extends AppCompatActivity {
private static final String TAG =
"TAG HERE";
IabHelper mHelper;
static final String ITEM_SKU = "android.test.purchased";
private Toolbar toolbar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
this.setContentView(R.layout.activity);
toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setNavigationOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View view) {
finish();
}
});
//Google play purchase test
String base64EncodedPublicKey =
"<My base 64 key>";
mHelper = new IabHelper(this, base64EncodedPublicKey);
Button button = (Button) findViewById(R.id.donate_btn);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mHelper.launchPurchaseFlow(Donate.this, ITEM_SKU, 10001,
mPurchaseFinishedListener, "mypurchasetoken");
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode,
Intent data)
{
if (!mHelper.handleActivityResult(requestCode,
resultCode, data)) {
super.onActivityResult(requestCode, resultCode, data);
}
}
Upvotes: 1
Views: 3826
Reputation: 770
It seems that you've not yet created a product on Google Play Developer Console. Do check out the below tutorials to help you with the process. These are step by step guides to implement In-App Billing in Android Studio:
http://www.techotopia.com/index.php/An_Android_Studio_Google_Play_In-app_Billing_Tutorial
https://developer.android.com/google/play/billing/index.html
Upvotes: 1
Reputation: 509
Since you are starting, I would also recommend to keep an eye in the Google Play Billing Library. It is in dev preview, but I would consider it, just to make it easier to migrate.
As Kavach said, check that you added the product. And, Add this and tell us what you get:
mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
public void onIabSetupFinished(IabResult result) {
if (!result.isSuccess()) {
Log.d(TAG, "Problem setting up In-app Billing: " + result);
}
}
});
Last, remember to dispose the helper in onDestroy:
if (mHelper != null) mHelper.dispose();
Upvotes: 1