Created
September 10, 2013 19:49
-
-
Save ec84b4/6514635 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void checkSiteForVersionChange() throws PackageManager.NameNotFoundException { | |
PackageInfo pInfo = getPackageManager().getPackageInfo(getPackageName(), 0); | |
final String currentVersion = pInfo.versionName; | |
class FtpTask extends AsyncTask<Void, Integer, Void> { | |
FTPClient con; | |
boolean succeed = false; | |
String error = ""; | |
String errorS = ""; | |
private Context context; | |
String newVersion = ""; | |
public FtpTask(Context context) { this.context = context; } | |
protected void onPreExecute() { | |
newVersion = currentVersion; | |
} | |
protected Void doInBackground(Void... args) { | |
try { | |
con = new FTPClient(); | |
con.connect(InetAddress.getByName("5.9.0.183")); | |
if (con.login("ftpUsername", "ftpPassword")) { | |
con.enterLocalPassiveMode(); // important! | |
InputStream inputStream; | |
BufferedReader r; | |
inputStream = con.retrieveFileStream(s + "versionPro" + s + "lastVersion"); | |
r = new BufferedReader(new InputStreamReader(inputStream)); | |
newVersion = r.readLine(); | |
inputStream.close(); | |
r.close(); | |
con.completePendingCommand(); | |
} | |
con.logout(); | |
con.disconnect(); | |
} catch (Exception e) { | |
error = e.toString(); | |
e.printStackTrace(); | |
} | |
return null; | |
} | |
protected void onPostExecute(Void result) { | |
if (!newVersion.equals(currentVersion)) { | |
showDialogExpire(); | |
editorMainPrefs.putString("currentVersion", newVersion ); | |
editorMainPrefs.commit(); | |
} | |
} | |
protected void onProgressUpdate(Integer... args) { | |
} | |
} | |
new FtpTask(MainActivity.this).execute(); | |
} | |
void showDialogExpire() { | |
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this); | |
builder.setTitle("Version notification"); | |
builder.setMessage("a new version of app has been published this version would you like to see the details ?"); | |
builder.setIcon(android.R.drawable.ic_dialog_alert); | |
builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() { | |
@Override | |
public void onClick(DialogInterface dialog, int which) { | |
// Uri uriUrl = Uri.parse("http://mydictionary.khaled.ir/"); | |
Uri uriUrl = Uri.parse("market://details?id=ir.khaled.mydictionary"); | |
Intent launchBrowser = new Intent(Intent.ACTION_VIEW, uriUrl); | |
startActivity(launchBrowser); | |
} | |
}); | |
builder.setNegativeButton("Not now", new DialogInterface.OnClickListener() { | |
@Override | |
public void onClick(DialogInterface dialog, int which) { | |
// editorMainPrefs.putInt("lastPost", lastPostNum); | |
} | |
}); | |
dialogExpire = builder.create(); | |
if (!dialogExpire.isShowing()) | |
dialogExpire.show(); | |
dialogExpire.setCanceledOnTouchOutside(false); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment