https://github.com/robotmedia/AndroidBillingLibrary
I've created separate Billing class:
public class Billing extends AbstractBillingActivity {
private static final String TAG = "Billing";
public Billing() {
}
@Override
public void onBillingChecked(boolean supported) {
Log.i(TAG, "Billing supported: " + supported);
}
once user presses button in Preferences I do:
Preference buyPref = (Preference) findPreference("pref_billing_buy");
buyPref.setOnPreferenceClickListener(new OnPreferenceClickListener() {
public boolean onPreferenceClick(Preference preference) {
if (Debug.Yes) Log.d(TAG, "Buying ad-free version");
Billing billing = new Billing();
billing.checkBillingSupported();
return true;
}
});
and getting the following error:
07-04 20:21:22.797: ERROR/AndroidRuntime(7172): FATAL EXCEPTION: main
07-04 20:21:22.797: ERROR/AndroidRuntime(7172): java.lang.NullPointerException
07-04 20:21:22.797: ERROR/AndroidRuntime(7172): at android.content.ContextWrapper.getPackageName(ContextWrapper.java:120)
07-04 20:21:22.797: ERROR/AndroidRuntime(7172): at net.robotmedia.billing.BillingService.getActionForIntent(BillingService.java:76)
07-04 20:21:22.797: ERROR/AndroidRuntime(7172): at net.robotmedia.billing.BillingService.createIntent(BillingService.java:69)
07-04 20:21:22.797: ERROR/AndroidRuntime(7172): at net.robotmedia.billing.BillingService.checkBillingSupported(BillingService.java:58)
07-04 20:21:22.797: ERROR/AndroidRuntime(7172): at net.robotmedia.billing.BillingController.checkBillingSupported(BillingController.java:114)
07-04 20:21:22.797: ERROR/AndroidRuntime(7172): at net.robotmedia.billing.AbstractBillingActivity.checkBillingSupported(AbstractBillingActivity.java:42)
07-04 20:21:22.797: ERROR/AndroidRuntime(7172): at spb.bridges.Preferences$1.onPreferenceClick(Preferences.java:212)
07-04 20:21:22.797: ERROR/AndroidRuntime(7172): at android.preference.Preference.performClick(Preference.java:812)
07-04 20:21:22.797: ERROR/AndroidRuntime(7172): at android.preference.PreferenceScreen.onItemClick(PreferenceScreen.java:198)
07-04 20:21:22.797: ERROR/AndroidRuntime(7172): at android.widget.AdapterView.performItemClick(AdapterView.java:284)
07-04 20:21:22.797: ERROR/AndroidRuntime(7172): at android.widget.ListView.performItemClick(ListView.java:3382)
07-04 20:21:22.797: ERROR/AndroidRuntime(7172): at android.widget.AbsListView$PerformClick.run(AbsListView.java:1696)
07-04 20:21:22.797: ERROR/AndroidRuntime(7172): at android.os.Handler.handleCallback(Handler.java:587)
07-04 20:21:22.797: ERROR/AndroidRuntime(7172): at android.os.Handler.dispatchMessage(Handler.java:92)
07-04 20:21:22.797: ERROR/AndroidRuntime(7172): at android.os.Looper.loop(Looper.java:144)
07-04 20:21:22.797: ERROR/AndroidRuntime(7172): at android.app.ActivityThread.main(ActivityThread.java:4937)
07-04 20:21:22.797: ERROR/AndroidRuntime(7172): at java.lang.reflect.Method.invokeNative(Native Method)
07-04 20:21:22.797: ERROR/AndroidRuntime(7172): at java.lang.reflect.Method.invoke(Method.java:521)
07-04 20:21:22.797: ERROR/AndroidRuntime(7172): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
07-04 20:21:22.797: ERROR/AndroidRuntime(7172): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
07-04 20:21:22.797: ERROR/AndroidRuntime(7172): at dalvik.system.NativeStart.main(Native Method)
What is wrong in my code?
Also, documentation says
When started your AbstractBillingActivity subclass will check if in-app billing is supported, followed by a call to onBillingChecked(boolean), which has to be implemented by the subclass.
But actually onBillingChecked()
is not called.
I should be reading documentation more carefully:
AbstractBillingActivity is an abstract activity that provides default integration with in-app billing.
So, it is started to work when I've replaced in my code extends Activity
with extends AbstractBillingActivity
(actually since I've used PreferenceActivity
, not just Activity
, I had to edit AbstractBillingActivity
also).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With