The story that the forced update could not be implemented

What is written

  1. Why the forced update could not be done
  2. How to get the version directly from the Play Store (alternative)

The reason why the forced update could not be done

--When you install the apk created in the internal test on the actual machine There were times when the dialog appeared and times when it did not appear. --The regularity of this event could not be found. ――The only thing I can say is that 13 hours have passed since I uploaded the apk to the internal test. Dialogs were often displayed.

How to get the version directly from the play store (alternative)

MainActivity.java


public class MainActivit {
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //Variable to put http request
        Uri.Builder builder = new Uri.Builder();
        AsyncHttpRequest task = new AsyncHttpRequest(this);
        //Find out the version of the app in the store
        task.execute(builder);
}

AsyncHttpRequest.java


//Asynchronous communication class will result in an error
public class AsyncHttpRequest extends AsyncTask<Uri.Builder, Void, String> {
    /**
     *Caller Activity
     */
    private Activity mainActivity;
    /**
     *Store app version
     */
    private String newVersion;
    /**
     *Shared resources
     */
    private SharedPreferences sharedPreferences;

    public AsyncHttpRequest(Activity activity) {
        //Caller activity
        this.mainActivity = activity;
    }

    @Override
    protected String doInBackground(Uri.Builder... builder) {
        //http request throwing process
        this.newVersion = "";
        String lang = getLocaleLang();
        try {
            //Information at the time of communication is summarized in a constant class
            this.newVersion = Jsoup.connect(PlayStoreConstants.STORE_BASE_URL + PlayStoreConstants.STORE_ID + "&locale=" + lang)
                    .timeout(PlayStoreConstants.TIMEOUT)
                    .userAgent("Mozilla/5.0 (Windows; U; WindowsNT 5.1; en-US; rv1.8.1.6) Gecko/20070725 Firefox/2.0.0.6")
                    .referrer(PlayStoreConstants.REFERRER)
                    .get()
                    .select(PlayStoreConstants.CSS_QUERY)
                    .get(7)
                    .ownText();
            //Save the version of the store and use it in Activity
            sharedPreferences = this.mainActivity.getSharedPreferences("version", MODE_PRIVATE);
            SharedPreferences.Editor editor = sharedPreferences.edit();
            editor.putString("storeVersion", this.newVersion);
            editor.apply();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return this.newVersion;
    }
   /**
     *Method to get the language of the terminal
     */
    public String getLocaleLang() {
        String localeLanguage = Locale.getDefault().getLanguage();
        return localeLanguage;
    }
}

PlayStoreConstants.java


/**
 *Play store communication constant class
 */
public class PlayStoreConstants {
    /**
     *Store URL
     */
    public static final String STORE_BASE_URL = "https://play.google.com/store/apps/details?id=";
    /**
     *Store ID
     */
    //https://play.google.com/store/apps/details?id=hoge part of hoge
    public static final String STORE_ID = "hoge";
    /**
     *Store details screen URL
     */
    public static final String STORE_DETAIL_URL = "market://details?id=";
    /**
     *Store communication timeout time
     */
    public static final int TIMEOUT = 30000;
    /**
     *Referrer header
     * (To prevent HTTP 403 errors)
     */
    public static final String REFERRER = "http://www.google.com";
    /**
     *CSS query
     */
    public static final String CSS_QUERY = ".hAyfc .htlgb";
}

Recommended Posts

The story that the forced update could not be implemented
The story that the Servlet could not be loaded in the Java Web application
The story that the request parameter from the iPhone application could not be obtained successfully with the Servlet
The story of stopping because the rails test could not be done
Correspond to "error that basic authentication does not pass" in the test code "The story that could not be done"
The case that "apt-get update" defined in "Dockerfile" could not be done at the time of "docker-compose build"
The story that I could not build after installing multiple Java on Windows
Solved the problem that the test could not be executed from the command line with spring-boot-starter-test
The story that the variable initialization method called in the Java constructor should not be overridden
[Gradle] The story that the class file did not exist in the jar file
Note that Insert could not be done with Spring Data JDBC
[Rails] A story that continued to incorrectly verify the reason why the update action did not pass (update)
The story that the build error did not stop when using Eclipse 2020
About the problem that the server can not be started with rails s
[Java] The story that the expected array was not obtained by the String.split method.
JSESSIONID could not be assigned to the URL when using Spring Security
After verifying the Monty Hall problem with Ruby, a story that I could understand well and did not understand well
[CentOS8] Since the javac command could not be used, install the java development environment.
I didn't know that inner classes could be defined in the [Java] interface
ValidationMessages.properties should not be multiple on the classpath
The story that docker had a hard time
The story that link_to is deep (cause unknown)
A story about making a Builder that inherits the Builder
Command that the registered information was not found
The story that the port can no longer be used in the Spring boot sample program
The story that did not disappear when I tried to delete mysql on ubuntu
[Spring Boot] The story that the bean of the class with ConfigurationProperties annotation was not found