【问题标题】:Implicit intents with startService are not safe InAppPurchasestartService 的隐式意图是不安全的 InAppPurchase
【发布时间】:2015-01-07 01:07:40
【问题描述】:

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

使用 startService 的隐式 Intent 不安全: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();
}

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

【问题讨论】:

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


    【解决方案1】:

    这样做:

      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 之前,也建议仅使用显式 Intent 来绑定服务。

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

    检查此行为更改here

    【讨论】:

    • 感谢您的回复,我的代码需要更改
    • 我使用的是 libgdx 而不是 android 而是一些 android 代码,mServiceConn 应该是什么?
    猜你喜欢
    • 1970-01-01
    • 2015-04-08
    • 2017-06-17
    • 1970-01-01
    • 1970-01-01
    • 2018-05-30
    • 1970-01-01
    • 2018-01-17
    • 2015-01-07
    相关资源
    最近更新 更多