Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In-App-Billing v3 when no network

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?

like image 681
Hartok Avatar asked Dec 16 '22 14:12

Hartok


2 Answers

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

GPlay IAP: no connection

like image 110
Hartok Avatar answered Jan 04 '23 17:01

Hartok


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;
    }
    
like image 41
Ben Max Rubinstein Avatar answered Jan 04 '23 15:01

Ben Max Rubinstein