Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# Change Log

## 31.3.0

* Added: `Tracking` sends app, screen and push analytics through `Analytics`; `start()` sends `first_open` once per install and `app_updated` after a version change
* Added: `Push.setTracking` sends `push_received` and `push_opened` with the message's `messageId`
* Added: `PushNotificationOpened.messageId`
* Added: `Account.createDevice`, `getDevice`, `deleteDevice` and `updateDeviceSession`, and the `Device` model
* Added: `Account.createLDAPSession`
* Added: `Session.userName`
* Added: `ImageFormat.AUTO` on `Storage.getFilePreview` and the avatar endpoints, serving avif or webp when the `Accept` header supports it
* Added: `OAuthProvider.NAVER` and `OAuthProvider.VIPPSSANDBOX`
* Updated: the SDK no longer declares `FOREGROUND_SERVICE` and `FOREGROUND_SERVICE_REMOTE_MESSAGING`; apps that call `Push.setForeground(true)` declare them
* Fixed: background push keeps waking up on phones that hold back expedited jobs
* Updated: requests send `X-Appwrite-Response-Format: 2.7.2`

## 31.2.0

* Added: `Client.setEnvironment` to act in a project environment; realtime connections carry it
Expand Down
41 changes: 33 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

![Maven Central](https://img.shields.io/maven-central/v/io.appwrite/sdk-for-android.svg?color=green&style=flat-square)
![License](https://img.shields.io/badge/license-BSD--3--Clause-blue.svg?style=flat-square)
![Version](https://img.shields.io/badge/api%20version-2.7.0-blue.svg?style=flat-square)
![Version](https://img.shields.io/badge/api%20version-2.7.2-blue.svg?style=flat-square)
[![X Account](https://img.shields.io/badge/follow-%40appwrite-000000?logo=x&style=flat-square)](https://x.com/appwrite)
[![Discord](https://img.shields.io/discord/564160730845151244?label=discord&style=flat-square)](https://appwrite.io/discord)

Expand All @@ -20,15 +20,15 @@ Kotlin DSL (`build.gradle.kts`):

```kotlin
dependencies {
implementation("io.appwrite:sdk-for-android:31.2.0")
implementation("io.appwrite:sdk-for-android:31.3.0")
}
```

Groovy (`build.gradle`):

```groovy
dependencies {
implementation 'io.appwrite:sdk-for-android:31.2.0'
implementation 'io.appwrite:sdk-for-android:31.3.0'
}
```

Expand Down Expand Up @@ -275,12 +275,26 @@ If `backgroundRestricted` is true, the user restricted the app's background usag

If the user force-stops the app (Settings > Force stop, and on some devices swiping it away from recents), Android cancels its alarms and jobs: nothing is delivered until the app is opened again, and the broker then replays what was sent meanwhile.

For immediate delivery even after a kill and during Doze, call `push.setForeground(true)` from the foreground: it adds a foreground service with a quiet ongoing notification. If you never enable it, you can remove the service from your merged manifest, so the Play Console does not ask you to declare it:
For immediate delivery even after a kill and during Doze, call `push.setForeground(true)` from the foreground: it adds a foreground service with a quiet ongoing notification. Foreground mode is opt-in, because Google Play asks apps that declare a `remoteMessaging` foreground service to justify it in the Play Console. To use it:

```xml
<service android:name="io.appwrite.services.PushService" tools:node="remove" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_REMOTE_MESSAGING" tools:node="remove" />
```
1. Add both permissions to `app/src/main/AndroidManifest.xml`, inside `<manifest>` and outside `<application>`:

```xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_REMOTE_MESSAGING" />

<application>
...
</application>
</manifest>
```

2. In the Play Console, complete the foreground service declaration for remote messaging, under App content > Foreground service permissions.

3. Call `push.setForeground(true)` while the app is on screen. Without the permissions it reports an error to `onError` and delivery stays on the scheduled runs.

The SDK already declares its `PushService`, so you don't add a `<service>`. To turn foreground mode off again, call `push.setForeground(false)`.

### Opening a tapped notification

Expand All @@ -296,6 +310,17 @@ val stop = push.onNotificationOpened { opened -> openSale(opened.data["saleId"])

A tap made while nothing listens is kept for `getInitialNotification()`. The tap intent still carries `Push.EXTRA_TOPIC` and `Push.EXTRA_PAYLOAD` for apps that read their activity's intent.

### Push analytics

Attach a `Tracking` to send `push_received` for each message a background subscription gets with a notification to show while the app is running, and `push_opened` for each tap reported by `getInitialNotification` or `onNotificationOpened`. Both carry the message's `messageId`, also exposed as `opened.messageId`.

```kotlin
val tracking = Tracking(Analytics(client), "<PROPERTY_ID>").also { it.start() }
val push = Push(client, context).setTracking(tracking)
```

`tracking.start()` also sends `first_open` once per install and `app_updated` on the first start after the app's version name changes. A reinstall or "clear data" counts as a new install. Call it from `Application.onCreate`. With another push provider, call `tracking.pushReceived(messageId = ..., campaign = ...)` and `tracking.pushOpened(...)` from its handlers. `push_received` is best effort: while the app is killed, its code often does not run when a notification arrives.

## Learn more

- [Android quick start](https://appwrite.io/docs/quick-starts/android) and [Java quick start](https://appwrite.io/docs/quick-starts/android-java)
Expand Down
29 changes: 29 additions & 0 deletions docs/examples/java/account/create-device.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
```java
import android.util.Log;

import io.appwrite.Client;
import io.appwrite.coroutines.CoroutineCallback;
import io.appwrite.exceptions.AppwriteException;
import io.appwrite.services.Account;

Client client = new Client(context)
.setEndpoint("https://<REGION>.cloud.appwrite.io/v1") // Your API Endpoint
.setProject("<YOUR_PROJECT_ID>"); // Your project ID

Account account = new Account(client);

try {
account.createDevice(
new CoroutineCallback<>((result, error) -> {
if (error != null) {
error.printStackTrace();
return;
}

Log.d("Appwrite", result.toString());
})
);
} catch (AppwriteException e) {
e.printStackTrace();
}
```
32 changes: 32 additions & 0 deletions docs/examples/java/account/create-ldap-session.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
```java
import android.util.Log;

import io.appwrite.Client;
import io.appwrite.coroutines.CoroutineCallback;
import io.appwrite.exceptions.AppwriteException;
import io.appwrite.services.Account;

Client client = new Client(context)
.setEndpoint("https://<REGION>.cloud.appwrite.io/v1") // Your API Endpoint
.setProject("<YOUR_PROJECT_ID>"); // Your project ID

Account account = new Account(client);

try {
account.createLDAPSession(
"<USERNAME>", // username
"password", // password
60L, // duration (optional)
new CoroutineCallback<>((result, error) -> {
if (error != null) {
error.printStackTrace();
return;
}

Log.d("Appwrite", result.toString());
})
);
} catch (AppwriteException e) {
e.printStackTrace();
}
```
30 changes: 30 additions & 0 deletions docs/examples/java/account/delete-device.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
```java
import android.util.Log;

import io.appwrite.Client;
import io.appwrite.coroutines.CoroutineCallback;
import io.appwrite.exceptions.AppwriteException;
import io.appwrite.services.Account;

Client client = new Client(context)
.setEndpoint("https://<REGION>.cloud.appwrite.io/v1") // Your API Endpoint
.setProject("<YOUR_PROJECT_ID>"); // Your project ID

Account account = new Account(client);

try {
account.deleteDevice(
"<DEVICE_ID>", // deviceId
new CoroutineCallback<>((result, error) -> {
if (error != null) {
error.printStackTrace();
return;
}

Log.d("Appwrite", result.toString());
})
);
} catch (AppwriteException e) {
e.printStackTrace();
}
```
30 changes: 30 additions & 0 deletions docs/examples/java/account/get-device.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
```java
import android.util.Log;

import io.appwrite.Client;
import io.appwrite.coroutines.CoroutineCallback;
import io.appwrite.exceptions.AppwriteException;
import io.appwrite.services.Account;

Client client = new Client(context)
.setEndpoint("https://<REGION>.cloud.appwrite.io/v1") // Your API Endpoint
.setProject("<YOUR_PROJECT_ID>"); // Your project ID

Account account = new Account(client);

try {
account.getDevice(
"<DEVICE_ID>", // deviceId
new CoroutineCallback<>((result, error) -> {
if (error != null) {
error.printStackTrace();
return;
}

Log.d("Appwrite", result.toString());
})
);
} catch (AppwriteException e) {
e.printStackTrace();
}
```
31 changes: 31 additions & 0 deletions docs/examples/java/account/update-device-session.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
```java
import android.util.Log;

import io.appwrite.Client;
import io.appwrite.coroutines.CoroutineCallback;
import io.appwrite.exceptions.AppwriteException;
import io.appwrite.services.Account;

Client client = new Client(context)
.setEndpoint("https://<REGION>.cloud.appwrite.io/v1") // Your API Endpoint
.setProject("<YOUR_PROJECT_ID>"); // Your project ID

Account account = new Account(client);

try {
account.updateDeviceSession(
"<DEVICE_ID>", // deviceId
"<SESSION_ID>", // sessionId
new CoroutineCallback<>((result, error) -> {
if (error != null) {
error.printStackTrace();
return;
}

Log.d("Appwrite", result.toString());
})
);
} catch (AppwriteException e) {
e.printStackTrace();
}
```
13 changes: 13 additions & 0 deletions docs/examples/kotlin/account/create-device.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
```kotlin
import io.appwrite.Client
import io.appwrite.coroutines.CoroutineCallback
import io.appwrite.services.Account

val client = Client(context)
.setEndpoint("https://<REGION>.cloud.appwrite.io/v1") // Your API Endpoint
.setProject("<YOUR_PROJECT_ID>") // Your project ID

val account = Account(client)

val result = account.createDevice()
```
17 changes: 17 additions & 0 deletions docs/examples/kotlin/account/create-ldap-session.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
```kotlin
import io.appwrite.Client
import io.appwrite.coroutines.CoroutineCallback
import io.appwrite.services.Account

val client = Client(context)
.setEndpoint("https://<REGION>.cloud.appwrite.io/v1") // Your API Endpoint
.setProject("<YOUR_PROJECT_ID>") // Your project ID

val account = Account(client)

val result = account.createLDAPSession(
username = "<USERNAME>",
password = "password",
duration = 60, // (optional)
)
```
15 changes: 15 additions & 0 deletions docs/examples/kotlin/account/delete-device.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
```kotlin
import io.appwrite.Client
import io.appwrite.coroutines.CoroutineCallback
import io.appwrite.services.Account

val client = Client(context)
.setEndpoint("https://<REGION>.cloud.appwrite.io/v1") // Your API Endpoint
.setProject("<YOUR_PROJECT_ID>") // Your project ID

val account = Account(client)

val result = account.deleteDevice(
deviceId = "<DEVICE_ID>",
)
```
15 changes: 15 additions & 0 deletions docs/examples/kotlin/account/get-device.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
```kotlin
import io.appwrite.Client
import io.appwrite.coroutines.CoroutineCallback
import io.appwrite.services.Account

val client = Client(context)
.setEndpoint("https://<REGION>.cloud.appwrite.io/v1") // Your API Endpoint
.setProject("<YOUR_PROJECT_ID>") // Your project ID

val account = Account(client)

val result = account.getDevice(
deviceId = "<DEVICE_ID>",
)
```
16 changes: 16 additions & 0 deletions docs/examples/kotlin/account/update-device-session.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
```kotlin
import io.appwrite.Client
import io.appwrite.coroutines.CoroutineCallback
import io.appwrite.services.Account

val client = Client(context)
.setEndpoint("https://<REGION>.cloud.appwrite.io/v1") // Your API Endpoint
.setProject("<YOUR_PROJECT_ID>") // Your project ID

val account = Account(client)

val result = account.updateDeviceSession(
deviceId = "<DEVICE_ID>",
sessionId = "<SESSION_ID>",
)
```
6 changes: 2 additions & 4 deletions library/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<!-- Foreground-service background Push delivery (Push.setForeground). Apps that never enable it can
remove PushService and these two permissions with tools:node="remove". -->
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_REMOTE_MESSAGING" />
<!-- Foreground mode (Push.setForeground) is opt-in: an app that enables it declares
FOREGROUND_SERVICE and FOREGROUND_SERVICE_REMOTE_MESSAGING itself. -->

<application>
<activity
Expand Down
6 changes: 4 additions & 2 deletions library/src/main/java/io/appwrite/Client.kt
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ class Client @JvmOverloads constructor(

val config: MutableMap<String, String>

internal val appContext: Context = context.applicationContext ?: context

internal val cookieJar = ListenableCookieJar(CookieManager(
SharedPreferencesCookieStore(context.getSharedPreferences(COOKIE_PREFS, Context.MODE_PRIVATE)),
CookiePolicy.ACCEPT_ALL
Expand All @@ -124,8 +126,8 @@ class Client @JvmOverloads constructor(
"x-sdk-name" to "Android",
"x-sdk-platform" to "client",
"x-sdk-language" to "android",
"x-sdk-version" to "31.2.0",
"x-appwrite-response-format" to "2.7.0"
"x-sdk-version" to "31.3.0",
"x-appwrite-response-format" to "2.7.2"
)
config = mutableMapOf()

Expand Down
Loading
Loading