--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.
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