Skip to content

Commit

Permalink
Simplify the use of the checkUpdate method
Browse files Browse the repository at this point in the history
  • Loading branch information
burgyl committed Sep 7, 2020
1 parent 158ddf4 commit 1628988
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,17 @@ In the onCreate of your activity, add this to check if there is an update at the

```java
if (savedInstanceState == null)
SelfUpdate.checkUpdate(this, "https://api.github.com/repos/burgyl/SelfUpdatingApp/releases/latest");
SelfUpdate.checkUpdate(this, "burgyl", "SelfUpdatingApp");
```

or this if you support API before 21 :

```java
if (savedInstanceState == null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
SelfUpdate.checkUpdate(this, "https://api.github.com/repos/burgyl/SelfUpdatingApp/releases/latest");
SelfUpdate.checkUpdate(this, "burgyl", "SelfUpdatingApp");
```

You have to adapt the above URL to match your repository.
You have to adapt the above username and repository.

### Resources

Expand Down
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ android {
applicationId "ch.lburgy.selfupdatingapp"
minSdkVersion 21
targetSdkVersion 29
versionCode 14
versionName "1.0.13"
versionCode 15
versionName "1.0.14"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ protected void onCreate(Bundle savedInstanceState) {

// Check if an update is available at startup
if (savedInstanceState == null)
SelfUpdate.checkUpdate(this, "https://api.github.com/repos/burgyl/SelfUpdatingApp/releases/latest");
SelfUpdate.checkUpdate(this, "burgyl", "SelfUpdatingApp");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@ public class SelfUpdate {

private static final String FILENAME_APK = "update.apk";
private static final String CONTENT_TYPE_APK = "application/vnd.android.package-archive";
private static final String BASE_URL = "https://api.github.com/repos/%s/%s/releases/latest";

private static AppCompatActivity activity;
private static SelfUpdateHttpClient httpClient;

public static void checkUpdate(AppCompatActivity activity, final String url) {
public static void checkUpdate(AppCompatActivity activity, String username, String repository) {
final String url = String.format(BASE_URL, username, repository);
SelfUpdate.activity = activity;
httpClient = new SelfUpdateHttpClient(activity);

Expand Down

0 comments on commit 1628988

Please sign in to comment.