본문 바로가기
안드로이드

업데이트체크

by Siang's 2019. 4. 3.
반응형

Gradle에
compile 'org.jsoup:jsoup:1.9.2'
추가

private class Version extends AsyncTask<Void, Void, String> {

@Override
protected void onPreExecute() {
super.onPreExecute();
}


@Override
protected String doInBackground(Void... params) {
// Confirmation of market information in the Google Play Store


try {
Document doc = Jsoup
.connect(
"https://play.google.com/store/apps/details?id=com.nose.r.calc")
.get();
Elements Version = doc.select(".htlgb ");
for (int i = 0; i < 7 ; i++)
{
rtn = Version.get(i).text();
if (Pattern.matches("^[0-9]{1}.[0-9]{1}.[0-9]{1}$", rtn))
{
break;
}
}
return rtn;
}
catch (IOException e)
{
e.printStackTrace();
}
return null;
}

@Override
protected void onPostExecute(String result) {
// Version check the execution application.
PackageInfo pi = null;
try
{
pi = getPackageManager().getPackageInfo(getPackageName(), 0);
}
catch (NameNotFoundException e)
{
e.printStackTrace();
}
verSion = pi.versionName;
rtn = result;
if (!verSion.equals(rtn))
{
alt_bld.setMessage("A new version is available. Please update to new version")
.setCancelable(false)
.setPositiveButton("Update",new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog,int id)
{
Intent marketLaunch = new Intent(Intent.ACTION_VIEW);
marketLaunch.setData(Uri.parse("https://play.google.com/store/apps/details?id=com.nose.r.calc"));
startActivity(marketLaunch);
finish();
}
});
AlertDialog alert = alt_bld.create();
alert.setTitle("Update Available");
alert.show();
}
super.onPostExecute(result);
}
}
반응형

'안드로이드' 카테고리의 다른 글

클립보드로 텍스트복사하기  (0) 2019.04.16
파일 입출력  (0) 2019.04.04
뒤로가기(back button) 종료 묻기  (0) 2019.03.20
DialogRadio  (0) 2019.03.20
깜빡이기  (0) 2019.03.19