1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-03-23 00:16:25 +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>
{productionSnippet?.trim() ? (
<Box sx={{ mt: 2 }}> <Box sx={{ mt: 2 }}>
<SectionHeader>Production settings</SectionHeader> <SectionHeader>Production settings</SectionHeader>
<Typography variant='body2'> <Typography variant='body2'>
We updated the Unleash code snippet to be production-ready. In order to validate the connection, we changed some
We recommend applying the following new settings to avoid settings that you might want to revert. We recommend the
exposing the API key and to follow best practices. following default settings.
</Typography> </Typography>
<Markdown components={{ code: CodeRenderer }}> <Markdown components={{ code: CodeRenderer }}>
{productionSnippet} {productionSnippet}
</Markdown> </Markdown>
</Box> </Box>
) : null}
{otherResourcesSnippet?.trim() ? (
<Box> <Box>
<SectionHeader>Additional resources</SectionHeader> <SectionHeader>Additional resources</SectionHeader>
<Typography variant='body2'> <Typography variant='body2'>
Now that weve validated the connection, you might want to Now that weve validated the connection, you might want
look into more advanced use cases and examples: to look into more advanced use cases and examples:
</Typography> </Typography>
<Markdown components={{ code: CodeRenderer }}> <Markdown components={{ code: CodeRenderer }}>
{otherResourcesSnippet} {otherResourcesSnippet}
</Markdown> </Markdown>
</Box> </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 {
val instance = DefaultUnleash(
androidContext = this,
unleashConfig = UnleashConfig.newBuilder(appName = "unleash-onboarding-android") unleashConfig = UnleashConfig.newBuilder(appName = "unleash-onboarding-android")
.proxyUrl("<YOUR_API_URL>") .proxyUrl("<YOUR_API_URL>")
.clientKey("<YOUR_API_TOKEN>") .clientKey("<YOUR_API_TOKEN>")
.pollingStrategy.interval(3000)
.metricsStrategy.interval(3000)
.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)