使用startService的隐式意图不是安全的InAppPurchase

时间:2015-01-06 14:15:37

标签: android in-app-purchase in-app-billing

我在我的应用程序中实现了应用程序内购买,我遇到了这个问题

  

使用startService的隐式意图不安全:Intent {act = com.android.vending.billing.InAppBillingService.BIND}   android.content.ContextWrapper.bindService:538   com.bulbulapps.bulbul.v3.BillingProcessor.bindPlayServices:106   com.bulbulapps.bulbul.v3.BillingProcessor.:99

我的代码:

getContext().bindService(new Intent("com.android.vending.billing.InAppBillingService.BIND"),  serviceConnection, Context.BIND_AUTO_CREATE);

但该行正在生成警告带有startService的隐式意图不安全。

付款弹出即将到来,付款也成功,但成功之后不会进入OnActivity结果

@Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) 
    {
        if (!bp.handleActivityResult(requestCode, resultCode, data))
            super.onActivityResult(requestCode, resultCode, data);

        Toast.makeText(getApplicationContext(), "onActivityResult", Toast.LENGTH_LONG).show();
}

我的要求是成功购买后必须处理。

1 个答案:

答案 0 :(得分:3)

这样做:

  Intent serviceIntent = new Intent("com.android.vending.billing.InAppBillingService.BIND");
  serviceIntent.setPackage("com.android.vending");
  bindService(serviceIntent, mServiceConn, Context.BIND_AUTO_CREATE);

仅使用显式intent来绑定服务,否则它将在Android 5.0及更高版本中引发异常。

在Android 5.0之前,建议仅使用显式意图绑定服务。

  

Context.bindService()方法现在需要一个显式的Intent,和   如果给出隐式意图,则抛出异常。确保您的应用是   安全,在启动或绑定服务时使用明确的意图,   并且不要为服务声明意图过滤器。

检查此行为更改here