I had a case like this and did so:
public class MainActivity ... {
// ...
private boolean mIsPremium = false;
static final String SKU_PREMIUM = "premium";
private IabHelper mHelper;
private String payload = "";
// ...
void complain(String message) {
alert("Error: " + message);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
isEmulator = Build.MODEL.contains("google_sdk") || Build.MODEL.contains("Emulator") || Build.MODEL.contains("Android SDK");
final String BASE64_KEY = "SUA CHAVE PUBLICA BASE_64";
if (!isEmulator) {
mHelper = new IabHelper(this, BASE64_KEY);
mHelper.enableDebugLogging(true);
Log.d(TAG, "Starting setup.");
mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
public void onIabSetupFinished(IabResult result) {
Log.d(TAG, "Setup finished.");
if (!result.isSuccess()) {
complain("Problem setting up in-app billing: " + result);
return;
}
if (mHelper == null) return;
Log.d(TAG, "Setup successful. Querying inventory.");
mHelper.queryInventoryAsync(mGotInventoryListener);
}
});
}
}
// ...
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == RC_REQUEST) {
if (mHelper == null)
return;
if (!mHelper.handleActivityResult(requestCode, resultCode, data)) {
super.onActivityResult(requestCode, resultCode, data);
} else {
Log.d(TAG, "onActivityResult handled by IABUtil.");
}
}
}
// ...
IabHelper.QueryInventoryFinishedListener mGotInventoryListener = new IabHelper.QueryInventoryFinishedListener() {
public void onQueryInventoryFinished(IabResult result, Inventory inventory) {
Log.d(TAG, "Query inventory finished.");
if (mHelper == null) return;
if (result.isFailure()) {
complain("Failed to query inventory: " + result);
return;
}
Log.d(TAG, "Query inventory was successful.");
Purchase premiumPurchase = inventory.getPurchase(SKU_PREMIUM);
mIsPremium = (premiumPurchase != null && verifyDeveloperPayload(premiumPurchase));
Log.d(TAG, "User is " + (mIsPremium ? "PREMIUM" : "NOT PREMIUM"));
}
};
IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener = new IabHelper.OnIabPurchaseFinishedListener() {
public void onIabPurchaseFinished(IabResult result, Purchase purchase) {
Log.d(TAG, "Purchase finished: " + result + ", purchase: " + purchase);
if (mHelper == null) return;
if (result.isFailure()) {
complain("Error purchasing: " + result);
return;
}
if (!verifyDeveloperPayload(purchase)) {
complain("Error purchasing. Authenticity verification failed.");
return;
}
Log.d(TAG, "Purchase successful.");
if (purchase.getSku().equals(SKU_PREMIUM)) {
// bought the premium upgrade!
Log.d(TAG, "Purchase is premium upgrade. Congratulating user.");
alert("Thank you for upgrading to premium!");
mIsPremium = true;
// aqui eu passo verdadeiro para a variável mIsPremium uma única vez e somente se o cara pagou mesmo
}
}
};
@Override
public void onDestroy() {
super.onDestroy();
if (mHelper != null) mHelper.dispose();
mHelper = null;
}
// ...
boolean verifyDeveloperPayload(Purchase p) {
payload = p.getDeveloperPayload();
return true;
}
}
In my case an app that gets the premium version, (which to remove ads), I just check if my item in the store was purchased and if yes, pass the value "true" to the variable mIsPremium, then when I'm going to call any other activity starting from my mainactivity I pass the value of this mIsPremium variable in a Bundle to read in that activity I'm calling.
By this method you check directly on the user's subscription to the specific app and it already does the control normally, without having to record it in the preferences of the device.
I hope it solves for you, here it works bluray, taking users "blind people" who always say they paid and the complaints did not disappear, but we all know that they paid nothing ...
Lucky for you