# Update Strategies

## Status Bar (default)

![](https://3807780648-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LEuZr4CqIWfHJ0tGCot%2F-LG6nRZNJnn6T-0olHvY%2F-LG6o8JX4Jt1h57j7cFX%2Fstatusbar.jpg?alt=media\&token=ff76c3c4-e469-440e-a126-27fd5fdbe406)

* `PushLink.setCurrentStrategy(StrategyEnum.STATUS_BAR);`
* Title message: "New version of \[App Name]"
* Description message: "Click to Update"
* Remains on the status bar until the installation happens.
* Clear the message if the admin changes back to an earlier version before the installation.

{% hint style="warning" %}
Check if your application has requested permission for notification or if you manually allowed it in Android settings.
{% endhint %}

## Friendly Popup (useful for full-screen apps)

![](https://3807780648-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LEuZr4CqIWfHJ0tGCot%2F-LG6oqOyc8FfRIbLbvwQ%2F-LG6p85ZaWw3U_pdKHjY%2Ffriendly.jpg?alt=media\&token=410b0699-d0ef-427c-b90b-ce310e2af450)

* `PushLink.setCurrentStrategy(StrategyEnum.FRIENDLY_POPUP);`
* Default message: "New version of \[App Name]. Do you want to update it?".
* Default buttons: \[Not Now]\[Update].
* It remains until the user presses \[Not Now] or \[Update] (The back button is blocked).
* Default reminder: 3 hours
* Hide the popup if the admin changes back to an earlier version before the installation.

{% hint style="info" %}
Don't forget to call `PushLink.setCurrentActivity(this);` inside `onResume`
{% endhint %}

```java
//Only for popups (FRIENDLY_POPUP or ANNOYING_POPUP)
//You MUST do this, otherwise popups will not work.
//Call it in the Activity you want to show the popup.
//You can show the popup in many screens by adding this in more than one Activity.
@Override
protected void onResume() {
  super.onResume();
  PushLink.setCurrentActivity(this);
}
```

## Annoying Popup (useful for full-screen when updates can't wait)

![](https://3807780648-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LEuZr4CqIWfHJ0tGCot%2F-LG6pZsoUNQnoQySklvh%2F-LG6pp5rP9vxQY-Ev7rz%2Fannoying.jpg?alt=media\&token=100569f9-5d2d-426b-b552-56741be334b0)

* `PushLink.setCurrentStrategy(StrategyEnum.ANNOYING_POPUP);`
* Default message: "For security reasons \[App Name] needs to be updated!"
* Default button: \[Update].
* Very insistent. It remains until the user presses \[Update] (The dismiss button is blocked).
* Hide the popup if the admin changes back to an earlier version before the installation.

{% hint style="info" %}
Don't forget to call `PushLink.setCurrentActivity(this);` inside `onResume`
{% endhint %}

```java
//Only for popups (FRIENDLY_POPUP or ANNOYING_POPUP)
//You MUST do this, otherwise popups will not work.
//Call it in the Activity you want to show the popup.
//You can show the popup in many screens by adding this in more than one Activity.
@Override
protected void onResume() {
  super.onResume();
  PushLink.setCurrentActivity(this);
}
```

## Custom (take complete control of your installation)

* `PushLink.setCurrentStrategy(StrategyEnum.CUSTOM);`
* When using the CUSTOM strategy, pushlink doesn't display anything and will broadcast two actions.
* `[your.package.name].pushlink.APPLY` is sent EVERY 30 seconds (more or less) when there is a downloaded but not applied new APK. The user has to handle those multiple broadcasts.
* `[your.package.name].pushlink.GIVEUP` is sent ONCE when the user gives up the update (in the web admin) before it has been applied.

{% hint style="info" %}
It is useful when the requirement is building a fancier and more modern notification, executing extra steps, or performing a silent background update.
{% endhint %}

```java
registerReceiver(new BroadcastReceiver() {
  @Override
  public void onReceive(Context context, Intent intent) {
    Uri apkUri = (Uri) intent.getExtras().get("uri");
    //enjoy the apk uri
    //notice this will be called every 30s (more or less). You need to handle this.
  }
}, new IntentFilter(getPackageName() + ".pushlink.APPLY"));
```

{% hint style="warning" %}
Do NOT register this receiver in AndroidManifest.xml. If you do that, CUSTOM will not work in **Android Oreo.**

<https://developer.android.com/about/versions/oreo/background>
{% endhint %}

## Background

* Installing APK without user interaction
* Silent updates
* Zero-touch updates
* KIOSK apps
* POS - Point of sale apps
* Dedicated devices
* COSU - Corporate Owned Single Use devices

![](https://3807780648-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LEuZr4CqIWfHJ0tGCot%2F-LG6pZsoUNQnoQySklvh%2F-LG6qLKcqFr3_ZSSOxUs%2Fbackground.jpg?alt=media\&token=e9b4afcf-7918-4e58-8f2b-1cb958953278)

[**Learn how to update apps in the background with CUSTOM strategy.**](https://github.com/pushlink/background-device-owner)

## Idle

Sometimes, you want to avoid undesired popups, notifications, or restarts during user interaction.

By default `idle` is `true` . This means the installation will start after the new APK download.

If you call `PushLink.idle(false)` , Pushlink will never fire the installation process.

Knowing that you can switch this value to control updates.

{% hint style="danger" %}
**Manually setting up this property can be dangerous**. If, for some reason, the program doesn’t set `idle` back to `true`Pushlink will lose the ability to update the app, and you’ll need to update the device manually.
{% endhint %}

## Customization

You can customize the built-in strategies like this:

```java
//If you use StatusBarStrategy
StatusBarStrategy sbs =  (StatusBarStrategy) PushLink.getCurrentStrategy();
sbs.setStatusBarTitle("Hello, there is a new version");
sbs.setStatusBarDescription("Click to be happy");

//If you use FriendlyPopUpStrategy
FriendlyPopUpStrategy fps =  (FriendlyPopUpStrategy) PushLink.getCurrentStrategy();
fps.setPopUpMessage("New version available");
fps.setNotNowButton("No, thanks!");
fps.setUpdateButton("Ok, lets go");
fps.setReminderTimeInSeconds(60 * 60); //one hour

//If you use AnnoyingPopUpStrategy
AnnoyingPopUpStrategy fps =  (AnnoyingPopUpStrategy) PushLink.getCurrentStrategy();
fps.setPopUpMessage("New version available");
fps.setUpdateButton("Ok, lets go");

```
