Get Started
Install Guides
Kotlin
you can integrate the ditto sdk into kotlin projects to develop native apps for the android platform for the api reference, see https //software ditto live/android/ditto/4 7 1/api reference/index html for a complete overview of the platforms, transports, and devices the kotlin sdk supports, see the docid\ zfxmlfmz2kkpgr83swcos to install the kotlin sdk and start syncing offline confirm that you meet the minimum requirements ( /#prerequisites ) prepare your environment for ditto ( /#setting up your environment ) configure your app permissions ( /#configuring permissions ) authenticate with the big peer and then start syncing offline ( /#integrating and initializing ) prerequisites following are the minimum requirements that must be met before attempting to install ditto android version 6 0 (marshmallow) minsdk version 23 0 compilesdk version 34 0 java development kit (jdk) version 11 0 setting up your environment include the maven central repository in your gradle file, and then synchronize it with your project from your project level build gradle file located in the android root directory, ensure the mavencentral() repository is included in the buildscript section bash buildscript { repositories { mavencentral() } dependencies { // classpath for plugins, etc } } synchronize your project with the gradle file by clicking file > sync project with gradle files configuring permissions the android operating system limits access to some device functionality for end user control and privacy to comply, configure your app to request permissions from end users at once during runtime include all necessary permissions required by android ( /#including required permissions ) proactively check permission availability to avoid unnecessary delay between granting location access and ditto recognizing the permission ( /#ensuring permissions setup ) including required permissions android requires certain permissions to be explicitly requested by the app to access features like bluetooth low energy (le) and wi fi aware these permissions must be included in the app's manifest file and requested from the end user at runtime for more information, see the official https //developer android com/guide/topics/permissions/overview documentation to include the necessary permissions required by android, and then do the following open the androidmanifest xml located in the android/app/src/main directory of your project within the \<manifest> tag, confirm that the following namespace declarations are included and, if needed, add them to the beginning of the file androidmanifest xml \<manifest xmlns\ tools="http //schemas android com/tools" xmlns\ android="http //schemas android com/apk/res/android"> within the same \<manifest> tag, just before the \<application> tag, add the following permissions androidmanifest xml \<uses permission android\ name="android permission bluetooth" android\ maxsdkversion="30" /> \<uses permission android\ name="android permission bluetooth admin" android\ maxsdkversion="30" /> \<uses permission android\ name="android permission bluetooth advertise" tools\ targetapi="s" /> \<uses permission android\ name="android permission bluetooth connect" tools\ targetapi="s" /> \<uses permission android\ name="android permission bluetooth scan" android\ usespermissionflags="neverforlocation" tools\ targetapi="s" /> \<uses permission android\ name="android permission access fine location" android\ maxsdkversion="32" /> \<uses permission android\ name="android permission access coarse location" android\ maxsdkversion="30" /> \<uses permission android\ name="android permission internet" /> \<uses permission android\ name="android permission access wifi state" /> \<uses permission android\ name="android permission access network state" /> \<uses permission android\ name="android permission change network state" /> \<uses permission android\ name="android permission change wifi multicast state" /> \<uses permission android\ name="android permission change wifi state" /> \<uses permission android\ name="android permission nearby wifi devices" android\ usespermissionflags="neverforlocation" tools\ targetapi="tiramisu" /> to limit the android os from granting select permissions, use the tools\ remove attribute to selectively exclude specific permissions from being affected by the android\ maxsdkversion behavior although using android\ maxsdkversion prevents unnecessary permission requests on older devices, it can also prevent your app from requesting the permission on devices running a newer android os version therefore, before restricting requests, consider how it may impact your app's compatibility and functionality on devices running newer android os versions for example, the following snippet shows a configuration that requests permissions from end users regardless of the sdk version on the peer device androidmanifest xml \<uses permission android\ name="android permission access fine location" tools\ remove="android\ maxsdkversion" /> \<uses permission android\ name="android permission access coarse location" tools\ remove="android\ maxsdkversion" /> save the androidmanifest xml file confirming sdk dependency and version ensure that your app’s build gradle file includes the ditto sdk dependency with the correct version bash implementation "live ditto\ ditto 4 7 1" ensuring permissions setup to ensure your app has the required permissions for sync, use the dittosyncpermissions helper class from the ditto sdk this helper class simplifies the process of requesting end user permissions at runtime with a single method call ( ensurepermissions ) for all necessary permissions handles any errors encountered during the permissions request process using the helper to use the dittosyncpermissions helper class import the dittosyncpermissions helper class in the main activity of your app import com ditto sdk dittosyncpermissions call the following in your activity or fragment's oncreate method fun checkpermissions() { val missing = dittosyncpermissions(this) missingpermissions() if (missing isnotempty()) { this requestpermissions(missing, 0) } } refresh permissions after location access on android, after granting location access, ditto may not immediately recognize the permission, causing a delay in syncing to address this, whenever a relevant permission changes, call refreshpermissions() to quickly check and start syncing with the new permissions fun checkpermissions() { val activity = requireactivity() val missing = dittosyncpermissions(activity) missingpermissions() if (missing isnotempty()) { activity requestpermissions(missing, 0) } } integrating and initializing using the application level context, integrate ditto into your app's oncreate method most apps require that ditto run as a singleton a singleton is an implementation ensuring your ditto instance accesses and shares a single object instance throughout your app to import the ditto instantiate ditto as a singleton object, create a custom application class subclass with the necessary initialization setup\ ceate and manage the ditto instance within the application class of your android app integrate ditto into your app's oncreate method cby doing so, you ensure that there is only one instance of ditto throughout the app's lifecycle, and it remains available for use by any activity or component that needs it this approach helps in efficient resource management and avoids unnecessary object instantiation and destruction add ditto to your application by placing it in your application oncreate method to ensure your app maintains a single ditto instance throughout its lifetime and prevents it from going out of scope or getting garbage collected, place ditto in the application level context instead of the context from any activity where you initially instantiated the ditto instance try { val androiddependencies = defaultandroiddittodependencies(context) val identity = dittoidentity onlineplayground( androiddependencies, appid = "replace me with your app id", token = "replace me with your playground token" ) dittologger minimumloglevel = dittologlevel debug ditto = ditto(androiddependencies, identity) ditto startsync() } catch (e dittoerror) { log e("ditto error", e message!!) } replace your app id and your playground token with your access credentials available from the portal (see docid 061yvo55q5yrbtwj5bsxc )