|
| 1 | +# messagevisor-example-android |
| 2 | + |
| 3 | +A small native Android application written in Kotlin, showing how to use the published [Messagevisor Java SDK](https://github.com/messagevisor/messagevisor-java). |
| 4 | + |
| 5 | +The application downloads a production Messagevisor datafile, creates an SDK instance with the ICU module, and renders plain and formatted translations. |
| 6 | + |
| 7 | +Learn more at [messagevisor.com](https://messagevisor.com). |
| 8 | + |
| 9 | +## Requirements |
| 10 | + |
| 11 | +Install Android Studio with Android SDK 36 and JDK 17. |
| 12 | + |
| 13 | +The project uses the Kotlin support built into Android Gradle Plugin 9, so it does not require the older Kotlin Android Gradle plugin. |
| 14 | + |
| 15 | +Messagevisor Java is published through GitHub Packages. Add your GitHub username and a personal access token with the `read:packages` scope to `~/.gradle/gradle.properties`: |
| 16 | + |
| 17 | +```properties |
| 18 | +gpr.user=YOUR_GITHUB_USERNAME |
| 19 | +gpr.key=YOUR_GITHUB_TOKEN |
| 20 | +``` |
| 21 | + |
| 22 | +Keep these credentials outside the repository. For GitHub Actions, grant the example repository read access to the Messagevisor Java packages. |
| 23 | + |
| 24 | +## Run the application |
| 25 | + |
| 26 | +1. Open the repository in Android Studio. |
| 27 | +2. Allow Gradle to sync and resolve Messagevisor Java 0.2.0. |
| 28 | +3. Select an Android emulator or connected device. |
| 29 | +4. Run the `app` configuration. |
| 30 | + |
| 31 | +## Messagevisor usage |
| 32 | + |
| 33 | +The application fetches this production datafile: |
| 34 | + |
| 35 | +```text |
| 36 | +https://messagevisor-example-cloudflare-pages.pages.dev/production/messagevisor-mobile-en-US.json |
| 37 | +``` |
| 38 | + |
| 39 | +The important SDK usage is in `MainActivity.kt`: |
| 40 | + |
| 41 | +```kotlin |
| 42 | +val m = Messagevisor.create( |
| 43 | + MessagevisorOptions.builder() |
| 44 | + .datafile(datafileJson) |
| 45 | + .timeZone("America/New_York") |
| 46 | + .addModule(IcuModule.create()) |
| 47 | + .build(), |
| 48 | +) |
| 49 | + |
| 50 | +val signIn = m.translate("auth.signin") |
| 51 | +val contact = m.translate( |
| 52 | + "nav.contact", |
| 53 | + mapOf("closingTime" to closingTime), |
| 54 | +) |
| 55 | +``` |
| 56 | + |
| 57 | +## Checks |
| 58 | + |
| 59 | +Run unit tests, Android lint, and a debug build with: |
| 60 | + |
| 61 | +```sh |
| 62 | +make build |
| 63 | +``` |
| 64 | + |
| 65 | +Learn more in the [Messagevisor Java SDK documentation](https://messagevisor.com/docs/sdks/java/). |
| 66 | + |
| 67 | +## License |
| 68 | + |
| 69 | +[MIT](LICENSE) |
0 commit comments