connect abstract method
Connects the NXFit user to the specified integration. This method supports two basic flows: those that require user authorization and those that do not.
Generates a URL to be used to be launched which puts the user through the integration authorize process. Part of the URL includes a redirect URL which is used to send the result of the authorize process back to your app. The redirect url contains the application package ID of the app initiating the authorize process. This is done to ensure that the application initiating the authorize process receives the result from the browser. An IntentFilter is required to make this work.
Get the Application Package ID
The application package ID may be retrieved via Context.getPackageName() and can be viewed in your app module's build.gradle file under: android.defaultConfig.applicationId.
android {
namespace 'com.example.app'
....
defaultConfig {
applicationId "com.example.app" // <-- this is the application package ID
minSdk 24
targetSdk 33
versionCode 1
versionName "1.0"
....
}
....
}
Create the IntentFilter with the Application Package ID
Define an intent-filter in the manifest to accept Intents with the scheme matching your application package ID. Example intent-filter:
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<application .... >
<activity .... >
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="com.example.app" />
</intent-filter>
</activity>
</application>
</manifest>
Initiate authorize process
To start the integration authorize process an Intent must be used to browse to the authorize page. The URI for the Intent is provided by IntegrationsManager.connect, along with necessary redirect URI that includes the application package ID. With the integration authorize URI in hand, use the CustomTabsIntent to navigate to the provided URL. Example:
await _integrationsManager.connect(integrationIdentifier, (authUri) async {
launchUrl(authUri);
});
Handle response
When a user completes the authorize procedure, an Intent will be sent to the associated activity. This can be handled either in the Activity's onCreate method (via getIntent()), or in the onNewIntent method. One recommendation is to set the launchMode of the receiving activity in your manifest to "singleTop". This will prevent launching the activity a second time if it's already running. The Intent contains the response and it must be processed by the IntegrationsManager via the IntegrationsManager.handleAuthorizeResponse method. Example:
override fun onNewIntent(intent: Intent?) {
super.onNewIntent(intent)
val data = intent?.data
data?.let {
integrationsManager.handleAuthorizeResponse(data.toString())
}
}
Implementation
Future<void> connect(String integrationIdentifier, Future<void> Function(Uri) authorizeAction);