7

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;
    }
user401183
  • 2,530
  • 4
  • 27
  • 25

2 Answers2

4

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.

prasanna
  • 1,887
  • 3
  • 20
  • 26
2

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.

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.

Community
  • 1
  • 1
theomega
  • 31,591
  • 21
  • 89
  • 127
  • i think this solution is better because many people have no energy to upgrade all apps from Google play or another ... like aptoid ... why your solution hasn't more vote? ... i think our apps should have ability to upgrade by itself automatically and prompt users to ... ask users if use this app , upgrade it. – saber tabatabaee yazdi Dec 06 '13 at 19:48