Android: add update button

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) { // Huh? Really? } return versionName; } 
+7
source share
2 answers

Just place the site somewhere with the release number, for example

 http://example.com/myapp/release 

If the release from this page is higher than the current version, enable the refresh button. You can use the "market: // search? Q = pname: com.example.myapp" Uri to tell the user to download your application.

+3
source

Put the file on the web server that contains the latest version-no, and also put the apk of your application on the web server. When the user wants to check the update, download the version file if the installed version is less than the latest, and then download apk and install it.

The main drawback: the user must enable "unsafe sources", otherwise you will not be able to install apk from your application.

You can also avoid installing apk by opening the market page, but the user will have to click "Update" there.

+2
source

All Articles