1
0
Fork 0
mirror of synced 2024-07-08 07:55:48 +12:00
appwrite/docs/sdks/android/GETTING_STARTED.md

69 lines
2.5 KiB
Markdown
Raw Normal View History

2021-06-01 22:17:50 +12:00
## Getting Started
### Init your SDK
<p>Initialize your SDK code with your project ID, which can be found in your project settings page.
```kotlin
2021-06-01 22:26:51 +12:00
import io.appwrite.Client
import io.appwrite.services.Account
2021-06-01 22:17:50 +12:00
2021-06-01 22:26:51 +12:00
val client = Client(context)
2021-06-01 22:17:50 +12:00
.setEndpoint("https://[HOSTNAME_OR_IP]/v1") // Your API Endpoint
.setProject("5df5acd0d48c2") // Your project ID
.setSelfSigned(true) // Remove in production
```
Before starting to send any API calls to your new Appwrite instance, make sure your Android emulators has network access to the Appwrite server hostname or IP address.
When trying to connect to Appwrite from an emulator or a mobile device, localhost is the hostname for the device or emulator and not your local Appwrite instance. You should replace localhost with your private IP as the Appwrite endpoint's hostname. You can also use a service like [ngrok](https://ngrok.com/) to proxy the Appwrite API.
### Make Your First Request
<p>Once your SDK object is set, access any of the Appwrite services and choose any request to send. Full documentation for any service method you would like to use can be found in your SDK documentation or in the API References section.
```kotlin
// Register User
2021-06-01 22:26:51 +12:00
val account = Account(client)
val user = account.create(
2021-06-01 22:17:50 +12:00
"email@example.com",
"password"
)
```
### Full Example
```kotlin
2021-06-01 22:26:51 +12:00
import io.appwrite.Client
import io.appwrite.services.Account
2021-06-01 22:17:50 +12:00
2021-06-01 22:26:51 +12:00
val client = Client(context)
2021-06-01 22:17:50 +12:00
.setEndpoint("https://[HOSTNAME_OR_IP]/v1") // Your API Endpoint
.setProject("5df5acd0d48c2") // Your project ID
.setSelfSigned(true) // Remove in production
2021-06-01 22:26:51 +12:00
val account = Account(client)
val user = account.create(
2021-06-01 22:17:50 +12:00
"email@example.com",
"password"
)
```
2021-06-01 22:26:51 +12:00
### Error Handling
The Apopwrite Android SDK raises `AppwriteException` object with `message`, `code` and `response` properties. You can handle any errors by catching `AppwriteException` and present the `message` to the user or handle it yourself based on provided error information. Below is an example.
```kotlin
try {
var response = account.create("email@example.com", "password")
Log.d("Appwrite response", response.body?.string())
} catch(e : AppwriteException) {
Log.e("AppwriteException",e.message.toString())
}
```
2021-06-01 22:17:50 +12:00
### Learn more
You can use followng resources to learn more and get help
2021-06-01 22:26:51 +12:00
- 🚀 [Getting Started Tutorial](https://appwrite.io/docs/getting-started-for-android)
2021-06-01 22:17:50 +12:00
- 📜 [Appwrite Docs](https://appwrite.io/docs)
2021-06-01 22:26:51 +12:00
- 💬 [Discord Community](https://appwrite.io/discord)
- - 🚂 [Appwrite Android Playground](https://github.com/appwrite/playground-for-android)