1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-25 00:07:47 +01:00

feat(onboarding): Android snippet (#8281)

This commit is contained in:
Tymoteusz Czech 2024-09-27 14:02:12 +02:00 committed by GitHub
parent ee9f8c8836
commit c502e99b85
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 90 additions and 38 deletions

View File

@ -19,7 +19,6 @@ const SpacedContainer = styled('div')(({ theme }) => ({
interface ISdkConnectedProps { interface ISdkConnectedProps {
sdk: Sdk; sdk: Sdk;
} }
export const SdkConnected: FC<ISdkConnectedProps> = ({ sdk }) => { export const SdkConnected: FC<ISdkConnectedProps> = ({ sdk }) => {
const { uiConfig } = useUiConfig(); const { uiConfig } = useUiConfig();
@ -42,30 +41,31 @@ export const SdkConnected: FC<ISdkConnectedProps> = ({ sdk }) => {
<Stepper active={2} steps={3} /> <Stepper active={2} steps={3} />
<Badge color='secondary'>3/3 - Test connection</Badge> <Badge color='secondary'>3/3 - Test connection</Badge>
</StepperBox> </StepperBox>
<Box sx={{ mt: 2 }}> {productionSnippet?.trim() ? (
<SectionHeader>Production settings</SectionHeader> <Box sx={{ mt: 2 }}>
<Typography variant='body2'> <SectionHeader>Production settings</SectionHeader>
We updated the Unleash code snippet to be production-ready. <Typography variant='body2'>
We recommend applying the following new settings to avoid In order to validate the connection, we changed some
exposing the API key and to follow best practices. settings that you might want to revert. We recommend the
</Typography> following default settings.
<Markdown components={{ code: CodeRenderer }}> </Typography>
{productionSnippet} <Markdown components={{ code: CodeRenderer }}>
</Markdown> {productionSnippet}
</Box> </Markdown>
<Box> </Box>
<SectionHeader>Additional resources</SectionHeader> ) : null}
<Typography variant='body2'> {otherResourcesSnippet?.trim() ? (
Now that weve validated the connection, you might want to <Box>
look into more advanced use cases and examples: <SectionHeader>Additional resources</SectionHeader>
</Typography> <Typography variant='body2'>
<Markdown components={{ code: CodeRenderer }}> Now that weve validated the connection, you might want
{otherResourcesSnippet} to look into more advanced use cases and examples:
</Markdown> </Typography>
</Box> <Markdown components={{ code: CodeRenderer }}>
{otherResourcesSnippet}
</Markdown>
</Box>
) : null}
</SpacedContainer> </SpacedContainer>
); );
}; };
// Use a default export for lazy-loading
export default SdkConnected;

View File

@ -1,21 +1,65 @@
1\. Install the SDK 1\. Install the SDK
```gradle
implementation("io.getunleash:unleash-android:\${unleash.sdk.version}")
// Enable required permissions ```gradle
implementation("io.getunleash:unleash-android:1")
```
2\. Enable required [permissions](https://developer.android.com/guide/topics/manifest/uses-permission-element)
```xml
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
``` ```
2\. Initialize Unleash 2\. Initialize Unleash in your application
```kotlin ```kotlin
val unleash = DefaultUnleash( class MyApplication: Application() {
androidContext = applicationContext, // Reference to your Android application context val unleash: Unleash by lazy {
unleashConfig = UnleashConfig.newBuilder(appName = "unleash-onboarding-android") val instance = DefaultUnleash(
.proxyUrl("<YOUR_API_URL>") androidContext = this,
.clientKey("<YOUR_API_TOKEN>") unleashConfig = UnleashConfig.newBuilder(appName = "unleash-onboarding-android")
.pollingStrategy.interval(3000) .proxyUrl("<YOUR_API_URL>")
.metricsStrategy.interval(3000) .clientKey("<YOUR_API_TOKEN>")
.build() .build()
) )
instance.start()
instance
}
override fun onTerminate() {
super.onTerminate()
unleash.close()
}
}
``` ```
3\. Check flag status
```kotlin
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val unleashInstance = (application as MyApplication).unleash
setContent {
var flagStatus by remember { mutableStateOf("loading") }
LaunchedEffect(Unit) {
while (isActive) {
val isFlagEnabled = unleashInstance.isEnabled("<YOUR_FLAG>")
flagStatus = if (isFlagEnabled) "enabled" else "disabled"
delay(3000L)
}
}
Text(text = "Flag is $flagStatus!")
}
}
}
```
---
---
- [SDK repository with documentation and example](https://github.com/Unleash/unleash-android)
- [Android SDK basic example](hhttps://github.com/Unleash/unleash-sdk-examples/tree/main/Android)

View File

@ -20,6 +20,10 @@ setInterval(() => {
``` ```
--- ---
### Production settings
In order to validate the connection, we changed some settings that you might want to revert. We recommend the following default settings.
```js ```js
const { initialize } = require('unleash-client'); const { initialize } = require('unleash-client');
@ -31,6 +35,10 @@ const unleash = initialize({
``` ```
--- ---
### Additional resources
Now that weve validated the connection, you might want to look into more advanced use cases and examples:
- [SDK repository with documentation](https://github.com/Unleash/unleash-client-node) - [SDK repository with documentation](https://github.com/Unleash/unleash-client-node)
- [Node.js SDK example with CodeSandbox](https://github.com/Unleash/unleash-sdk-examples/tree/main/NodeJS) - [Node.js SDK example with CodeSandbox](https://github.com/Unleash/unleash-sdk-examples/tree/main/NodeJS)
- [Node.js SDK tutorial](https://dev.to/reeshee/how-to-implement-feature-flags-in-nodejs-using-unleash-3907) - [Node.js SDK tutorial](https://dev.to/reeshee/how-to-implement-feature-flags-in-nodejs-using-unleash-3907)