This is due to the verifyPurchase () method in the Security class, which has been changed in new patches. Let me show you exactly what the problem is:
Security Class Changes
OLD CODE
public static boolean verifyPurchase(String base64PublicKey, String signedData, String signature) { if (signedData == null) { Log.e(TAG, "data is null"); return false; } boolean verified = false; if (!TextUtils.isEmpty(signature)) { PublicKey key = Security.generatePublicKey(base64PublicKey); verified = Security.verify(key, signedData, signature); if (!verified) { Log.w(TAG, "signature does not match data."); return false; } } return true; }
New code
public static boolean verifyPurchase(String base64PublicKey, String signedData, String signature) { if (TextUtils.isEmpty(signedData) || TextUtils.isEmpty(base64PublicKey) || TextUtils.isEmpty(signature)) { Log.e(TAG, "Purchase verification failed: missing data."); return false; } PublicKey key = Security.generatePublicKey(base64PublicKey); return Security.verify(key, signedData, signature); }
According to what I searched and tested from the new code,
Why is this happening because we will not receive any signature while we use a dummy product, for example "android.test.purchased". Therefore, in the old code, it works well, because we returned even if the signature is not specified, and for the new code we return false.
more information on null or blank signature data from link1 and link2
Therefore, I suggest that you simply replace the method of the old verifyPurchase () method instead of the New Code method.
I think New Code will work fine for a real product, but not in a dummy product. But so far I have not tested the real product.
Let me learn more about this, why they changed the code and what is the purpose of this.
EDIT:
BuildConfig.DEBUG will also provide you with a test purchase solution.
In the verifyPurchase field, I changed return false to:
Log.e(TAG, "Purchase verification failed: missing data."); if (BuildConfig.DEBUG) { return true; } return false;
but you should know that use this only in a test case.
This will return true if you have a debug build and no signature data. Since BuildConfig.DEBUG will be false in the assembly, this should be OK. But it is better to remove this code after everything is debugged.
I edited some code in the verifyPurchase () method, check it below:
public static boolean verifyPurchase(String base64PublicKey, String signedData, String signature) { if (signedData == null) { Log.e(TAG, "data is null"); return false; } if (TextUtils.isEmpty(signedData) || TextUtils.isEmpty(base64PublicKey) || TextUtils.isEmpty(signature)) { Log.e(TAG, "Purchase verification failed: missing data."); if (BuildConfig.DEBUG) { Log.d("DeBUG", ">>>"+BuildConfig.DEBUG); return true; } return false; } PublicKey key = Security.generatePublicKey(base64PublicKey); return Security.verify(key, signedData, signature); }
I got this from the GvS answer android in checking the purchase of the billing application.
Hope this will be helpful to you.