Search code examples
androidin-app-purchasein-app-billing

Implicit intents with startService are not safe InAppPurchase


I've implemented In-app purchase in my application and I face this problem

Implicit intents with startService are not safe: 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

My code:

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

but that line is generating a warning Implicit intents with startService are not safe.

Payment popup coming and payment also success, but after success it is not coming to OnActivity result

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

My requirement is I have to handle after successful purchase.


Solution

  • Do it like this:

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

    Use explicit intent only to bind a service otherwise it will throw exception in Android 5.0 and above.

    Before Android 5.0 also it is suggested to use explicit intent only to bind a service.

    The Context.bindService() method now requires an explicit Intent, and throws an exception if given an implicit intent. To ensure your app is secure, use an explicit intent when starting or binding your Service, and do not declare intent filters for the service.

    Check this behavior change here.