In-app-billing v3 when there is no network

In-App-Billing v3 is implemented in my Android application with its assistants.

When there is no network, I am stuck on an ugly gray screen after the start of the purchase.

Is there any way to handle this in our application?

I currently prohibit startup purchases when I do not receive SKU details from the Store. However, the connection may change after startup. I did not find a way to find out if the Google Play service is available or not.

Thank you for your help!

enter image description here

Similar problem: What is the response code for invoicing in V3 after the timeout?

+4
source share
4 answers

The new Google Play app v4.0.25 now correctly handles this:

GPlay IAP: no connection

+7
source

Like NIkolay’s suggestion, a workaround might be to check connectivity before starting a request.

If you want to try, here is a snippet of code that may help you;

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

    ACCESS_NETWORK_STATE is required to access the ConnectivityManager (for network connections in general) and ACCESS_WIFI_STATE allows access to the WifiManager (to control Wi-Fi connectivity).

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

     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; } 
+5
source

Hold the ping file to check for a communication failure by calling the read line in a loop. Do this before launching the “Buy” function (or during the “purchase”), etc., to check the connection before allowing the gray screen to appear after confirmation.

As an alternative to reading content, you can use the default timeout. If the bytes accept ≠ 0, continue; if = 0 after 8 seconds (or n-seconds) of display error.

This will make your “ugly gray screen” display as if there wasn’t enough network connection to complete the server check (and therefore the transaction), you will receive an error instead of running the store function itself.

This is essentially manual logic testing for refusing to communicate over the network - not just reading the presence or status of the network, as sometimes the network may work fine, but the network connection will be an error or too slow to host applications / transactions / view / etc . This method does not require additional permissions to confirm network communication.


Here is an example of using the code to check for the presence of a web page / location without downloading a file (bandwidth savings), but it still allows you to throw an exception or execute "IF / THEN". ((Source: http://singztechmusings.wordpress.com/2011/05/26/java-how-to-check-if-a-web-page-exists-and-is-available/ ))

 import java.net.HttpURLConnection; import java.net.URL; public class URLUtils { public static void main(String[] args) { System.out.println(URLUtils.checkIfURLExists("http://www.google.com/")); } public static boolean checkIfURLExists(String targetUrl) { HttpURLConnection httpUrlConn; try { httpUrlConn = (HttpURLConnection) new URL(targetUrl) .openConnection(); httpUrlConn.setRequestMethod("HEAD"); // Set timeouts in milliseconds httpUrlConn.setConnectTimeout(30000); httpUrlConn.setReadTimeout(30000); // Print HTTP status code/message for your information. System.out.println("Response Code: " + httpUrlConn.getResponseCode()); System.out.println("Response Message: " + httpUrlConn.getResponseMessage()); return (httpUrlConn.getResponseCode() == HttpURLConnection.HTTP_OK); } catch (Exception e) { System.out.println("Error: " + e.getMessage()); return false; } } } 
+2
source

Unfortunately, all proposed solutions still require checking the network connection before starting a payment request, which either provides a significant unnecessary delay when a user connects, or an even greater delay (waiting for a timeout) when the user is not connected or requires permission, which otherwise would be would not be all applications. Plus, as already noted, there is a danger of a false identification of the absence (or presence) of a network connection.

In addition, some versions of Google Play (for some versions of Android at least) already cope with the lack of a network connection (for example, Nexus7 displays a dialog called "Error" with the text "No connection", as you would expect and desire). And since the update process of the Google Play application is automated, it is hoped that Google will eventually solve this problem for those versions of the application that are currently exposing it, and when this happens, applications with aggressive solutions will want to have these solutions removed and will have unnecessary overhead until they do.

Given the foregoing, it is entirely possible that the best solution would be to simply add the selected text to the dialog or view that contains the button that the user uses to start the purchase, saying

"Please make sure your device is connected to the Internet. Click the" Back "button if you encounter any problems."

Pressing the back button on the gray screen appears to cause the screen to disappear, and calls onActivityResult () to call with RESULT_CANCELED, as if the user had canceled the payment dialog. so that the user exits the gray screen.

As low-tech as this approach, it seems to me that this is the best of many options.

0
source

All Articles