Skip to main content

Hybrid Apps

The DataSapien Mobile SDK supports Flutter and React Native, providing the same functionality as native iOS and Android with framework-specific setup.

Step 1: Register DataSapien project

Before you can add Mobile SDK to your app, you need to create your account and log into the Orchestrator using your registered domain.

Your authentication keys and host URLs will be provided after registration. You can obtain the required configuration keys by contacting the DataSapien team.

Flutter

Step 2: Add Flutter dependencies

Add the DataSapien packages and Flutter config to your pubspec.yaml:

dependencies:
datasapien_sdk: ^0.14.0
# Optional: Health module for health data collection
datasapien_sdk_health: ^0.14.0

flutter:
config:
enable-swift-package-manager: true

Run flutter pub get; both packages resolve.

Note: Only add datasapien_sdk_health if you need health data collection features. If you use the health package, you'll need to configure the health-related native settings for iOS and Android (see Step 3 below). For package details, see datasapien_sdk and datasapien_sdk_health.

Step 3: Native platform configuration

The native implementation for iOS and Android is the same as for Native Apps. Complete the following platform-specific configuration.

iOS

Prerequisites

  • Xcode 16.4 or higher
  • Target iOS 17.0 or higher
  • Set up a physical Apple device

Configure Info.plist

Add URL schemes and associated domains for OAuth flow:

Option 1: Custom URL Scheme (Recommended for development)

<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLSchemes</key>
<array>
<string>your-app-scheme</string>
</array>
</dict>
</array>

Option 2: Associated Domains (Recommended for production)

<key>com.apple.developer.associated-domains</key>
<array>
<string>applinks:<YOUR_OAUTH_REDIRECT_HOST></string>
</array>

Note: For Associated Domains, you'll also need to enable the capability in Xcode (see below) and configure an apple-app-site-association file on your server.

Optional: Installed Apps (for MeData collection)

<key>LSApplicationQueriesSchemes</key>
<array>
<string>itms-apps</string>
<string>itms</string>
</array>

Optional: Health Permissions (only if using datasapien_sdk_health)

<key>NSHealthShareUsageDescription</key>
<string>This app needs access to your health data to provide personalized insights.</string>

Enable Capabilities

  • Associated Domains: Add the capability and your OAuth redirect domain: applinks:<YOUR_OAUTH_REDIRECT_HOST>
  • HealthKit: Add only if you're using the health module.

Android

Prerequisites

  • Android Studio (latest stable version)
  • Minimum SDK: 26 (Android 8.0)
  • Target SDK: 36 (Android 15)
  • Java 17 or higher
  • Gradle 8.0 or higher

Dependencies are brought in by the Flutter packages; you do not add the DataSapien Maven repository or Gradle dependencies manually.

Update AndroidManifest.xml

Add your Application class and required components in android/app/src/main/AndroidManifest.xml:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<!-- Required permissions -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />

<!-- Optional: For installed_apps MeData collection -->
<!-- Option 1: Query all packages (requires Google Play approval) -->
<uses-permission
android:name="android.permission.QUERY_ALL_PACKAGES"
tools:ignore="QueryAllPackagesPermission" />

<!-- Option 2: Query specific packages (recommended) -->
<queries>
<package android:name="com.example.app1" />
<package android:name="com.example.app2" />
</queries>

<!-- Optional: Health data permissions (only if using datasapien_sdk_health) -->
<uses-permission android:name="android.permission.health.READ_HEIGHT" />
<uses-permission android:name="android.permission.health.READ_WEIGHT" />
<uses-permission android:name="android.permission.health.READ_STEPS" />
<uses-permission android:name="android.permission.health.READ_TOTAL_CALORIES_BURNED" />
<uses-permission android:name="android.permission.health.READ_BASAL_METABOLIC_RATE" />
<uses-permission android:name="android.permission.health.READ_ACTIVE_CALORIES_BURNED" />
<uses-permission android:name="android.permission.health.READ_HEART_RATE" />
<uses-permission android:name="android.permission.health.READ_SLEEP" />
<uses-permission android:name="android.permission.health.READ_OXYGEN_SATURATION" />
<uses-permission android:name="android.permission.health.READ_RESTING_HEART_RATE" />
<uses-permission android:name="android.permission.health.READ_VO2_MAX" />

<application
android:name=".MyApplication"
... >

<!-- Required: OAuth redirect activity -->
<activity
android:name="com.datasapien.dssdk.managedapi.ui.OAuthRedirectActivity"
android:exported="true">
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="<YOUR_OAUTH_REDIRECT_HOST>"
android:pathPrefix="<YOUR_OAUTH_PATH>"
android:scheme="https" />
</intent-filter>
</activity>

<!-- Required: LlamaCpp service for on-device LLM inference -->
<service
android:name="com.datasapien.dssdk.intelligence.engine.llama.LlamaCppService"
android:enabled="true"
android:exported="false"
android:process=":llm" />
</application>
</manifest>

Step 4: Initialize SDK in your Flutter app

Initialize the SDK from Dart in your Flutter app (for example in main() or before running the app):

import 'package:datasapien_sdk/datasapien_sdk.dart';

// Initialize
final config = DataSapienConfig.builder()
.setAuth(
authUrl: 'https://your-auth-server.com/',
authClientId: 'your-client-id',
authClientSecret: 'your-client-secret',
authScope: 'api://your-client-id/.default',
)
.setHostUrl('https://api.datasapien.com/')
.setMediaUrl('https://media.datasapien.com/')
.build();

await DataSapien.initialize(config);
await DataSapien.setup();

Replace the URLs and client credentials with the values provided by the DataSapien team. We recommend calling DataSapien.setup() at each app launch because the SDK fetches only optimized deltas.

React Native

Documentation for React Native will be added later.