4

In-App-Billing v3 is implemented in my Android App, with its Helpers.

When there's no network, I'm stuck on an ugly grey screen after initiating a purchase.

Is there a way to handle this in our app?

Currently, I disable purchases at launch when I don't receive SKU details from the Store. However, the connectivity can change after the launching. I have not found a way to know if Google Play Service was available or not.

Thanks for your help!

enter image description here

Similar issue: Which response code does in-app billing V3 return upon timeout?

Community
  • 1
  • 1
Hartok
  • 2,147
  • 20
  • 37
  • 1
    Check connection state when they hit the 'Buy' button and display error dialog, etc.? – Nikolay Elenkov Feb 18 '13 at 02:09
  • I thought I missed something in the configuration of IAB. So I was expecting a solution within IAB and its helpers code. But you're right, checking connection state is a reliable solution. – Hartok Feb 18 '13 at 13:20
  • The Google Play client doesn't really handle lack of Internet access (or slow speeds) too well, so you wouldn't want to pass control there if that is the case. – Nikolay Elenkov Feb 18 '13 at 13:31
  • i didnt face that before, maybe try to sign the app and try will fix it. – Mohammad Ersan Feb 19 '13 at 13:05
  • The issue still occurs when app is signed with release key, but not published. Android 2.3.7, Google Play app 3.10.10. – Hartok Feb 21 '13 at 02:14
  • 1
    FYI, a complicating (also ameliorating) factor is that some versions of Android / Google Play *do* handle the absence of network connectivity correctly, by putting up a dialog titled "Error" that says "No connection." For example, my Nexus7 (running JB) does this, and when you tap OK on that dialog, it does call your activity's onActivityResult() method (indicating cancellation of the purchase, just as if the user had tapped the back button from the usual payment dialog). OTOH, my Nexus One running Gingerbread has the grey screen that you report. – Carl Feb 27 '13 at 14:56

3 Answers3

7

New Google Play app v4.0.25 now properly handles this:

GPlay IAP: no connection

Hartok
  • 2,147
  • 20
  • 37
5

Like NIkolay has suggested, a workaround could be checking for connectivity prior to initiating the request.

If you want to try that, here's a piece of code that may help you;

  1. First you will need to add some permissions to your AndroidManifest.xml file; specifically the android.permission.ACCESS_NETWORK_STATE or android.permission.ACCESS_WIFI_STATE.

    ACCESS_NETWORK_STATE is needed for accessing ConnectivityManager (for network connections in general) and ACCESS_WIFI_STATE allows access to WifiManager (for managing Wi-Fi connectivity).

    <!-- Needed for Reachability testing / wifi vs 3g uploading -->
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    
  2. Second, check out this method to determine network status

    public static boolean isNetworkAvailable(Context context) {
        ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo netInfo = cm.getActiveNetworkInfo();
        if (null == netInfo || !netInfo.isConnected()) {
            return false;
        }
        return true;
    }
    
Ben Max Rubinstein
  • 1,803
  • 1
  • 13
  • 15
  • This is definitely a workaround. OP needs a way to detect communication failure, not just the presence of a network connection. – David Snabel-Caunt Feb 20 '13 at 17:09
  • It's a possible solution. But here a simple case not handled: connected to a Wifi spot, but without any internet connection. This case can be frequent in airports or hotels where user must often sign in with his browser. – Hartok Feb 21 '13 at 04:59
  • There's no need for `android.permission.ACCESS_WIFI_STATE` if you only use ConnectivityManager. See http://developer.android.com/reference/android/net/ConnectivityManager.html#getActiveNetworkInfo() – MagicMicky Dec 27 '13 at 20:12
0

Unfortunately, all proposed solutions thus far require checking for a network connection prior to launching the payment request, which either provides a significant unnecessary delay when the user is connected, and an even longer delay (waiting for a timeout) when the user is not connected, or, requires permissions that not all apps would otherwise need. Plus, as already noted, there's a danger of falsely identifying a lack of (or the presence of) network connectivity.

Also, some versions of Google Play (for certain versions of Android at least) already handle a lack of network connectivity correctly (e.g., Nexus7 shows a dialog titled "Error" with the text "No connection," as one would expect and desire). And, since the process of updating the Google Play app is automated, there is some hope that Google will eventually address this problem for those versions of the app that presently exhibit it, and when it does, apps with aggressive solutions will want to have those solutions removed, and will have unneeded overhead until they do.

Given the above, it may well be that the best solution would be to just add some highlighted text to the dialog or view that holds the button that is used by the user to launch a purchase, saying

"Please be sure your device is connected to the Internet. Tap the back button if you encounter any problems."

Tapping the back button at the grey screen seems to cause the screen to disappear, and causes onActivityResult() to be invoked with RESULT_CANCELED, just as if the user had canceled from the payment dialog. so that will get the user out of the grey screen.

As low-tech as this approach is, to me it seems like the best of a bad lot of options.

Carl
  • 15,445
  • 5
  • 55
  • 53
  • The first solution does require any delay. So it's an efficient check. I was not aware of the existence of Google Play apps that handles this kind of error. My tests were done on a HTC Desire (Nexus One twin). – Hartok Mar 04 '13 at 03:52
  • Google deploys updates for Google Play very fast. The reason why this network error handling is not an older devices is probably because Google Play cannot request new permissions once installed. – Hartok Mar 04 '13 at 03:56
  • I hadn't known about that inability of Google Play to request new permissions; you'd think that it would be able to, considering that users were never asked to approve those permissions in the first place. It's true that my Nexus One has the latest version of the Google Play app, and yet it still exhibits the problem, so this being permission-related could explain the problem's continuance, although I'm not sure what role permissions would play in causing or resolving this issue. – Carl Mar 04 '13 at 11:35
  • Yes, it's true that the first solution does not require a delay, but it requires permissions that I would personally not otherwise need in my own apps. I intended to communicate that either permissions or delays would be required for the various approaches, but not both. – Carl Mar 04 '13 at 11:40