Configuration

Configure the Sahha SDK for use in your project

Configure

You will need to configure the Sahha SDK before you can use it.

🚧

Configure the SDK immediately

The Sahha SDK must be configured immediately on app launch.

Choose your specific platform from the options below.

import SwiftUI
import Sahha

@main
struct MyApp: App {
  
  // Configure Sahha inside `init` of your app's `App` view.
    
    init() {
        let settings = SahhaSettings(environment: .development)
        Sahha.configure(settings)
    }

    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }
}
import Sahha

// Configure Sahha inside `application didFinishLaunchingWithOptions` of your app's `AppDelegate`.

func application(_: UIApplication, didFinishLaunchingWithOptions _: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool {
   let settings = SahhaSettings(
      environment: .development, // Required - .development for testing
      sensors: [.sleep], // Optional - defaults to all sensors
      postSensorDataManually: false // Optional - defaults to false
   )
   Sahha.configure(settings) {
        // SDK is ready to use
        print("SDK Ready")
   }
  return true
}
import sdk.sahha.android.source.*

// Configure Sahha inside `onCreate` of your app's `MainActivity`.

class MainActivity : ComponentActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        // You can specify optional custom notification settings
        val notificationSettings = SahhaNotificationConfiguration(
            icon = R.drawable.ic_test, // The icon id must match the filename you add to the project
            title = "Custom Title",
            shortDescription = "Custom description",
        )

        val settings = SahhaSettings (
            environment = SahhaEnvironment.development,
            notificationSettings = notificationSettings, // Optional - defaults to null
            sensors = [.pedometer, .sleep], // Optional - defaults to all avaialable sensors
            postSensorDataManually = false, // Optional - defaults to false
        )

        Sahha.configure(application, settings) { error, success ->
            if (error != null) {
                println(error)
            } else {
                println(success.toString())
            }
        }
    }
}
import 'package:sahha_flutter/sahha_flutter.dart';

// Configure Sahha inside `initState` of your app's `AppState`.

class _MyAppState extends State<MyApp> {

  @override
  void initState() {
      super.initState();

    // Optional - Android only
    var notificationSettings = {
      'icon': 'Custom Icon',
      'title': 'Custom Title',
      'shortDescription': 'Custom Description'
    };

      // Use custom values
      SahhaFlutter.configure(
          environment: SahhaEnvironment.production, // Required - .development for testing
          sensors: [SahhaSensor.device], // Optional - defaults to all sensors
          postSensorDataManually: true, // Optional - defaults to false
          notificationSettings: notificationSettings) // Optional - Android only
      .then((success) => {
          debugPrint(success.toString())
        })
      .catchError((error, stackTrace) => {
          debugPrint(error.toString())
        });
  }
}
import Sahha, { SahhaEnvironment, SahhaSensor } from "sahha-react-native";

// Configure Sahha inside your App's `export function`.

export default function App() {
  // Use custom values
  const settings = {
    environment: SahhaEnvironment.production, // Required -  .development for testing
    // Optional - Android only
    notificationSettings: {
      icon: "ic_test",
      title: "Test Title",
      shortDescription: "Test description.",
    },
    sensors: [SahhaSensor.sleep, SahhaSensor.pedometer], // Optional - defaults to all sensors
    postSensorDataManually: true, // Optional - defaults to false
  };
  Sahha.configure(settings, (error: string, success: boolean) => {
    console.log(`Success: ${success}`);
    if (error) {
      console.error(`Error: ${error}`);
    }
  });
}
import {
  Sahha,
  SahhaSensor,
  SahhaEnvironment,
  SahhaSettings,
} from "sahha-capacitor";

// Configure Sahha inside your App's `export function`.

const App: React.FC = () => {
  const settings: SahhaSettings = {
    environment: SahhaEnvironment.production, // Required -  .development for testing
    sensors: [SahhaSensor.sleep], // Optional - defaults to all sensors
    postSensorDataManually: true, // Optional - defaults to false
    // Optional - Android only
    notificationSettings: {
      icon: "ic_test",
      title: "Test Title",
      shortDescription: "Test description.",
    },
  };

  Sahha.configure({ settings: settings })
    .then((data) => {
      console.log(`Success: ${data.success}`);
    })
    .catch((error: Error) => {
      console.error(error);
    });
};

Environment Settings

The SahhaEnvironment determines if the SDK connects to the development or production server of the API. Setting this incorrectly will send data to the wrong server.

SahhaEnvironmentDescription
developmentFor development and testing
productionFor submission to the App store
public enum SahhaEnvironment: String {
    case development
    case production
}
enum class SahhaEnvironment {
    development,
    production
}
enum SahhaEnvironment {
  development,
  production
}
enum SahhaEnvironment {
  development,
  production
}

Sensor Settings

You can specify which sensors for the Sahha SDK to use. To optimize your analysis result, we suggest enabling all sensors. Leave this value null to enable all sensors by default.

Some sensors are not available on all platforms.

SahhaSensorDescriptionAndroidiOS
sleepFor tracking sleep patterns
pedometerFor tracking walking patterns
deviceFor tracking device usage patternsX
public enum SahhaSensor: String, CaseIterable {
    case sleep
    case pedometer
    case device
}
enum class SahhaSensor {
    device,
    sleep,
    pedometer
}
enum SahhaSensor {
  sleep,
  pedometer,
  device
}
enum SahhaSensor {
  sleep,
  pedometer,
  device
}

Sensor Data Settings

If you would like to handle posting of sensor data to the Sahha API manually, set postSensorDataManually to true. You will then need to post sensor data to the Sahha API manually by calling postSensorData.

If you would like the Sahha SDK to handle posting of sensor data to the Sahha API automatically, set postSensorDataManually to false.

postSensorDataManually defaults to false.

postSensorDataManuallyDescription
trueYou will post sensor data to the Sahha API manually by calling postSensorData
falseThe Sahha SDK will post sensor data to the Sahha API automatically

Notifications

You can customize notifications for any platform that includes an Android app.

👍

You can customize notifications for the following platforms:

  • Android
  • Flutter (Android only)
  • React Native (Android only)
  • Ionic / Capacitor (Android only)

iOS apps not supported


Custom Notification Icon

You can add an optional custom notification icon to your Android app.

📘

How to create app icons with Image Asset Studio

Click here for more info

Step 1) Open your project in Android Studio.

Step 2) With the app folder highlighted, selectFileNewImage Asset.

Step 3) Select Notification Icons for Icon Type, enter a Name, select Image as Asset Type and alter the Padding as desired.

Step 4) This page can typically be left as it is. Select Finish.


Custom Notification Settings

You can specify optional custom notificationSettings. If notificationSettings are not specified, then the app will use the default notification settings.

val notificationSettings = SahhaNotificationConfiguration(
    icon = R.drawable.ic_test, // The icon id must match the filename you add to the project
    title = "Custom Title",
    shortDescription = "Custom description",
)

Default Notification Settings

If custom notificationSettings are not specified, then the app will use the default notification settings. If custom notificationSettings are only partially specified, then the app will use the default notification settings.The app will fill in the missing notification parameters with default values. E.g. if an icon and title are provided but a shortDescription is not, then the shortDescription will use the default value.

val icon = R.drawable.ic_sahha_no_bg // The Sahha logo
val title = "Analytics are running"
val shortDescription = "Swipe for options to hide this notification."