12

I am getting lot of exceptions in crash report for my app in google store. Can somebody hep me what could cause this? I am using android:targetSdkVersion=19

java.lang.SecurityException: Requires READ_PHONE_STATE: Neither user 10131 nor current process has android.permission.READ_PHONE_STATE.
    at android.os.Parcel.readException(Parcel.java:1546)
    at android.os.Parcel.readException(Parcel.java:1499)
    at com.android.vending.billing.IInAppBillingService$Stub$Proxy.getSkuDetails(IInAppBillingService.java:251)
    at com.inapp.util.IabHelper.querySkuDetails(IabHelper.java:920)
    at com.inapp.util.IabHelper.queryInventory(IabHelper.java:550)
    at com.inapp.util.IabHelper.queryInventory(IabHelper.java:522)
    at com.inapp.util.IabHelper$2.run(IabHelper.java:617)
    at java.lang.Thread.run(Thread.java:818)
rpattabi
  • 9,984
  • 5
  • 45
  • 53
Vijay Bansal
  • 141
  • 4
  • Its probably what the exception says, your missing the READ_PHONE_STATE permission – J j Jun 30 '16 at 19:14
  • 2
    I think it's more likely it's in the Manifest but it hasn't been granted on Marshmallow devices. https://developer.android.com/training/permissions/requesting.html – DeeV Jun 30 '16 at 19:18
  • Keep in mind that even though you're targeting Api-19, users on Marshmallow can manually revoke the permission after installation. – Daniel Nugent Jun 30 '16 at 19:41
  • You need to ask for permissions programmatically if you want to support devices with Android M and above. Check out my answer here.http://stackoverflow.com/questions/35856432/asking-for-permissions-while-using-locationmanager/35857017#35857017 – Shadab Ansari Jun 30 '16 at 19:54
  • @ShadabAnsari He's targeting api-19, so all permissions are granted at install time, even on Marshmallow. – Daniel Nugent Jun 30 '16 at 20:03
  • 5
    Looking for a solution to this aswell. IAP does not require READ_PHONE_STATE, not according the docs, yall. This also does not happen for every device, most work just fine. The issue is currently being ignored here: https://productforums.google.com/forum/#!topic/play/4LigT3eyQgk – Андрей Вахрушев Jul 07 '16 at 07:45
  • Seeing this issue as well for IAP. I don't want to have to add READ_PHONE_STATE to my app - that's a dangerous level permission and lots of users will think I'm stealing data or something. – mliu Jul 15 '16 at 18:39
  • 3
    I'm also getting this a lot since a few days. Seems to be related to IAP and Google Play Services. Here you can find more people with the same issue: https://github.com/googlesamples/android-play-billing/issues/26 – Steffen Jul 18 '16 at 00:53
  • Do you still have this issue? – Vektor88 Sep 19 '16 at 06:09

2 Answers2

3

Although Google has confirmed to have shipped the update having the fix, but the following try catch block at least prevents the crash

int querySkuDetails(String itemType, Inventory inv, List<String> moreSkus)
                                throws RemoteException, JSONException {
        logDebug("Querying SKU details.");
        ArrayList<String> skuList = new ArrayList<String>();
        skuList.addAll(inv.getAllOwnedSkus(itemType));
        if (moreSkus != null) {
            for (String sku : moreSkus) {
                if (!skuList.contains(sku)) {
                    skuList.add(sku);
                }
            }
        }

        if (skuList.size() == 0) {
            logDebug("queryPrices: nothing to do because there are no SKUs.");
            return BILLING_RESPONSE_RESULT_OK;
        }

        // NullPointer crash reported through PlayStore forums
        if (mService == null) {
            return IABHELPER_SERVICE_UNAVAILABLE;
        }

        Bundle querySkus = new Bundle();
        querySkus.putStringArrayList(GET_SKU_DETAILS_ITEM_LIST, skuList);

        try {
                    Bundle skuDetails = mService.getSkuDetails(3, mContext.getPackageName(), itemType, querySkus);
                    if (!skuDetails.containsKey(RESPONSE_GET_SKU_DETAILS_LIST)) {
                        int response = getResponseCodeFromBundle(skuDetails);
                        if (response != BILLING_RESPONSE_RESULT_OK) {
                            logDebug("getSkuDetails() failed: " + getResponseDesc(response));
                            return response;
                        }
                        else {
                            logError("getSkuDetails() returned a bundle with neither an error nor a detail list.");
                            return IABHELPER_BAD_RESPONSE;
                        }
                    }

                    ArrayList<String> responseList = skuDetails.getStringArrayList(RESPONSE_GET_SKU_DETAILS_LIST);

                    for (String thisResponse : responseList) {
                        SkuDetails d = new SkuDetails(itemType, thisResponse);
                        logDebug("Got sku details: " + d);
                        inv.addSkuDetails(d);
                    }
                    return BILLING_RESPONSE_RESULT_OK;
                }
                // Security Exception due to missing permissions reported through PlayStore forums
                catch (SecurityException e)
                {
                    return IABHELPER_SERVICE_UNAVAILABLE;
                }
}

Please note that the only change in the method int querySkuDetails(String itemType, Inventory inv, List moreSkus) is the try catch block of the Security Exception. Rest everything remains same.

Varun Bhatia
  • 4,326
  • 32
  • 46
-7

Add the appropriate permission in your AndroidManifest.xml

<uses-permission android:name="android.permission.READ_PHONE_STATE" />
Eclipse22
  • 553
  • 5
  • 11