2011-07-04 3 views
5

https://github.com/robotmedia/AndroidBillingLibraryComment utiliser la bibliothèque de facturation Android?

J'ai créé séparé la classe de facturation: bouton

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); 
    } 

fois que l'utilisateur appuie dans les préférences que je fais:

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; 
     } 
    }); 

et obtenir l'erreur suivante:

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) 

Quel est le problème dans mon code?

En outre, la documentation indique

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.

Mais en fait onBillingChecked() est pas appelé.

Répondre

2

je devrais être en train de lire la documentation plus attentivement:

AbstractBillingActivity is an abstract activity that provides default integration with in-app billing.

Ainsi, il est commencé à travailler quand je l'ai remplacé dans mon code extends Activity avec extends AbstractBillingActivity (en fait depuis que je l'ai utilisé PreferenceActivity, pas seulement Activity, J'ai dû éditer AbstractBillingActivity aussi).

+1

Bonne prise à propos de PreferenceActivity. Nous devrions ajouter plus de classes de commodité pour les sous-classes d'activité les plus courantes (PreferenceActivity, ListActivity, etc.). – hpique

Questions connexes