gpt4 book ai didi

android - 如何使用安卓计费库?

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:08:07 25 4
gpt4 key购买 nike

https://github.com/robotmedia/AndroidBillingLibrary

我创建了单独的 Billing 类:

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

一旦用户在首选项中按下按钮,我就会:

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

出现以下错误:

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)

我的代码有什么问题?

此外,文档说

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.

但实际上 onBillingChecked() 并没有被调用。

最佳答案

我应该更仔细地阅读文档:

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

因此,当我在代码中将 extends Activity 替换为 extends AbstractBillingActivity 时,它就开始工作了(实际上是因为我使用了 PreferenceActivity,不仅仅是 Activity,我还必须编辑 AbstractBillingActivity

关于android - 如何使用安卓计费库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6573973/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com