Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: adding an upgrade button

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;
    }
like image 664
user401183 Avatar asked Feb 20 '11 18:02

user401183


2 Answers

Just put up a site somewhere with release number like

http://example.com/myapp/release

If the releasenum from that page is higher than your current release, enable the upgrade button. You can use the "market://search?q=pname:com.example.myapp" Uri to point the user to download your app.

like image 94
prasanna Avatar answered Nov 13 '22 11:11

prasanna


Put a file on a webserver which contains the most recent version-no, and also put the apk of your app on a webserver. When the user wants to check for an upgrade, download the version-file, if the currently installed version is smaller than the most recent one then download the apk and install it.

  • See this SO-Post how to install an apk.
  • See here how to download a file

Major disadvantage: The user has to enable "unsafe sources", otherwise you can't install the apk from your application.

You could also avoid having to install the apk by opening the market-page, but the user will have to click "Upgrade" there.

like image 35
theomega Avatar answered Nov 13 '22 12:11

theomega