大家好:)我正在尝试在我的应用程序中实现应用内计费,并观看GitHub中RobotMedia的自述文件我已经完成了以下操作:
我正在尝试:

aba = new AbstractBillingActivity() {

        @Override
        public String getPublicKey() {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public byte[] getObfuscationSalt() {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public void onSubscriptionChecked(boolean supported) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onRequestPurchaseResponse(String itemId, ResponseCode response) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onPurchaseStateChanged(String itemId, PurchaseState state) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onBillingChecked(boolean supported) {
            // TODO Auto-generated method stub

        }
    };

当我试着做的时候:
aba.checkBillingSupported();

它对变量“aba”产生了nullpointerexception
编辑
我做到了:
public class Index extends AbstractBillingActivity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_index);

        checkBillingSupported();


        Button buy = (Button) findViewById(R.id.compra);
        buy.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {

                requestPurchase("android.test.purchased");


            }
        });

    }

    @Override
    public byte[] getObfuscationSalt() {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public String getPublicKey() {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public void onBillingChecked(boolean supported) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onSubscriptionChecked(boolean supported) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onPurchaseStateChanged(String itemId, PurchaseState state) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onRequestPurchaseResponse(String itemId, ResponseCode response) {
        // TODO Auto-generated method stub

    }

}

最佳答案

如果直接使用BillingController,则还需要实现IBillingObserver,特别是onPurchaseIntent
您可能想从查看DungeonsRedux(示例代码)开始,并可能首先使用AbstractBillingActivity来熟悉iab。
关于你最近的编辑,你不应该用构造器创建活动,除非你真的是认真的。由于变量为空,您似乎得到了空指针异常,这可能与使用new创建活动有关。
我强烈建议您从IAB API guide开始,一旦您熟悉了iab的核心概念,那么就转到库。

07-26 07:27