Is it possible to add a button to an app that tries to upgrade the app?
I'd love to be able to add a button to the preferences that looks for a newer version of the app. If there is one available, I'd like that button to become active so the user can click it to upgrade.
UPDATE: Thanks this got me going the right direction. I took a pretty simple approach. Here's the final code for including a "Check for Updates" button to the preferences.
In the preference XML:
<Preference
android:title="Check for Updates"
android:summary="Version: 1.3"
android:key="versionPref" />
In java:
// select button
Preference versionPref = findPreference("versionPref");
// set string
String versionName = getVersionName();
versionPref.setSummary("Version: "+versionName);
// attach to button
versionPref.setOnPreferenceClickListener(new OnPreferenceClickListener() {
public boolean onPreferenceClick(Preference preference) {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("market://search?q=pname:com.mycompany.myapp"));
startActivity(intent);
return true;
}
});
//Get string name
public String getVersionName() {
String versionName = "";
try {
versionName = getPackageManager().getPackageInfo(getPackageName(), 0).versionName;
} catch (NameNotFoundException e) {
// Huh? Really?
}
return versionName;
}