Can I add a button to an application that is trying to update the application?
I would like to add a button to the settings that are looking for a newer version of the application. If there is one available, I would like this button to become active, so the user can click it to refresh.
UPDATE: Thanks, it made me go in the right direction. I made a fairly simple approach. Here is the final code to enable the Check for Updates button in the settings.
In the XML preference:
<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 the name of the string
public String getVersionName() { String versionName = ""; try { versionName = getPackageManager().getPackageInfo(getPackageName(), 0).versionName; } catch (NameNotFoundException e) {
user401183
source share