anjlab检查从mainactivity购买

时间:2017-09-01 19:08:27

标签: android

我有这个课程用于结算:

public class billing extends Activity implements BillingProcessor.IBillingHandler {
    BillingProcessor bp;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.billing);

        bp = new BillingProcessor(this, "YOUR LICENSE KEY FROM GOOGLE PLAY CONSOLE HERE", this);

anjlab项目。

问题是我想检查用户是否从主要活动购买了我的产品。我正在尝试:

来自我的主要活动:

public class MainActivity extends BaseActivity {
...
//check purchase
BillingProcessor bp = new BillingProcessor(); //cannot resolve constructor
String productId="android.test.purchased";
TransactionDetails transactionDetails = bp.getPurchaseTransactionDetails(productId);
if (transactionDetails != null) {
    //Already purchased
}

-

为什么无法解析构造函数?我应该改变什么才能使它发挥作用?

2 个答案:

答案 0 :(得分:1)

如果您想检查用户是否实际购买了您的产品,那么您可以尝试 -

bp.isPurchased("Your Product / SKU Name");
如果已购买其他商品true

,则

返回false

答案 1 :(得分:0)

BillingProcessor bp = new BillingProcessor(); cannot be resolved, because there is no empty constructor available in **BillingProcessor class**

Inside BillingProcessor类只有两个可用的公共构造函数。

public BillingProcessor(Context context, String licenseKey, IBillingHandler handler)
    {
        this(context, licenseKey, null, handler);
    }

    public BillingProcessor(Context context, String licenseKey, String merchantId,
                            IBillingHandler handler)
    {
        this(context, licenseKey, merchantId, handler, true);
    }

您可以查看BillingProcessor类here