Flutter Guide
Plugin for flutter applications that utilizes Credify Collection SDK to collect data from device, supports only android platform.
This plugin acts as a wrapper for Credify Native SDK.
To gain access application will need user permission on these permissions:
SDK collection method will only collect data if the permission is granted, for example if user only accepted location and call logs, collection method will return a JSOn object with these two only to avoid exceptions
- SMS:
READ_SMS
- Minimum SDK Required 21
- Target SDK Required 31+
General usage guide
1. Install the SDK
Install the package using the following command
flutter pub add credify_collection_sms_sdk
2. Reviewing permissions
Make sure that your application inclues the following permissions in android manifest file:
<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.USE_BIOMETRIC" />
3. Importing library
You can start using the SDK using the following import
import 'package:credify_collection_sdk/credify_collection.dart';
//...
4. Initializing the SDK
To start using SDK functionalities SDK must be initialized with some identifiers that will be used to tag information collected with the user that is using the application. Usually initialization should take place right after user login.
Sample Initialization
final _credifyPlugin = CredifyCollection();
// initialize collection plugin
try{
dynamic initializeResult = await _credifyPlugin.initialize(
"<your token here>");
// ideally after login, user identifier must be set to tag all collected data with the user
await _credifyPlugin.setUserIdentifier("<user ID here>");
// or use this method tag all collected data with more user-related info
await _credifyPlugin.setUserInfo("<user ID here>", "<user full name here>", "<user phone number here>");
} catch (error) {
collectedData = encoder.convert(error);
// when an exception is thrown it probably means there was a critical error while initializing, check error code and error message inside the exception for more information.
loading = false;
}
5. Requesting permissions
User consent/approval on permissions is needed to run the collection method, to do so you can choose one of the following options:
- Ask user for permission from inside the client application code (can be useful if client application wants to show custom UI before asking for permissions)
- Or you can simply call the SDK method RequestPermissions which requests permissions for collection items that your application can collect.
_credifyPlugin.requestPermissions()
6. Requesting permissions
SDK provies a method to get status of each enabled collection type and permissions that are accepted and/or rejected, this method can be used to check which collection types will be collected and sent.
Permission status will be checked for all collection types that are enabled.
Sample Permissions Status Response
{
"accepted_permissions": ["android.permission.READ_SMS"],
"rejected_permissions": [],
"enabled_collection": {
"SMS_LOG": true,
"DEVICE_INFO": true
}
}
Sample Permissions Status Request
_credifyPlugin.GetPermissionsStatus()
7. Collecting and Sending Data
After gaining proper approval, you can can call CollectData to collect and send collected data securely.
try{
dynamic data = await _credifyPlugin.collectData();
final object = json.decode(data);
// data returned contains a JSON Object that contains each type of data collected and status of collecting and sending the data
// result 200 means success
// other results might indicate error, please check the error codes below for more information.
} catch (error) {
collectedData = encoder.convert(error);
// Always catch exceptions here as it will contain an error and error code that can help identify the underlying issue.
// can be due to a null context or destroyed activity, check exception for more debugging information.
loading = false;
}
Error Codes and Debugging
Initialization error codes
Error Code | Description | Recommendation |
---|---|---|
100 | Activity or Context null | Make sure the activity is not null and avoid placing initialization in splash activity |
104 | Credify API configuration responded but configuration is null or mismatching | Update your Credify SDK |
Invalid token, response code ... | Credify API configuration responded with non-success status code | Review your token and make sure it is valid |
103 | Unhandled Exception | Check logcat logs for more info |
Collection error codes
These are returned on each data type collected
Error Code | Description | Recommendation |
---|---|---|
200 | Data was collected and sent properly | |
100 | Activity or Context null | Make sure the activity is not null and avoid placing initialization in splash activity |
104 | Credify API configuration responded but configuration is null or mismatching | Update your Credify SDK |
103 | Unhandled Exception | Check logcat logs for more info |
other values | Means that data was collected properly, but a network/service error occurred while sending | Get in touch with Credify Team to investigate further |
Debugging
Simply run your application in debug mode and filter logcat logs with the tag name "CredifySDK", logs messages under this tag contains log of all steps taken by the SDK and contains informational logs, logical errors, handled native exceptions and unhandled native exceptions.