Integrating with Tizen
This guide provides instructions on how to integrate the Honeygain SDK into your Tizen application using the provided files and associated service.
Don't forget to generate your Honeygain SDK API Key and download SDK from Developers dashboard first.
Prerequisites
- Tizen development environment set up
- Basic knowledge of Tizen app development
- Honeygain SDK files (
sdk.js
,background.js
)
Integration Steps
1. Add SDK Files
Copy sdk.js
and background.js
files to your application source directory.
2. Include the SDK background service in your config.xml file
In your application config file (e.g., config.xml
), include the SDK background service inside of a <widget>
element:
<tizen:service id="<yourpackage>.BackgroundService">
<tizen:content src="<path/to/background.js>" />
<tizen:name>BackgroundService</tizen:name>
<tizen:description>Service Application</tizen:description>
<tizen:metadata key="meta-key" value="meta-value" />
<tizen:category name="http://tizen.org/category/service" />
</tizen:service>
- Replace
<yourpackage>
with your package name. - Replace
<path/to/background.js>
with path to your copiedbackground.js
file.
Please remember this service id value as it going to be needed in further steps.
3. Include the SDK in your app
In your main HTML file (e.g., index.html
), include the SDK(sdk.js
file):
<script src="path/to/sdk.js"></script>
4. Initialize the SDK
To initialize the Honeygain SDK, you need to create an instance of the HgSdk
class with your API key. Here’s an example of how to do this in your main JavaScript file:
var sdk = new HgSdk({
apiKey: '<your-api-key>',
backgroundServiceId: '<background-service-id>',
applicationId: '<your-application-id>'
});
- Replace
<your-api-key>
with API key you got while creating the app. - Replace
<background-service-id>
with id from step #2. - Replace
<your-application-id>
with application id from yourconfig.xml
file.
IMPORTANT! If invalid configuration is provided initialization throws error so you should wrap this inside of a try
block.
5. Use methods of SDK
Once you have initialized the SDK, you can use its methods to interact with the Honeygain service. Below are the methods provided by the class:
sdk.start() // Starts SDK if opted in or consented
sdk.stop() // Stops SDK
sdk.isRunning() // Returns a boolean status is sdk already running
sdk.optIn() // Opts in without showing consent screen
sdk.optOut() // Opts out and stops SDK
sdk.requestConsent() // Shows consent screen
sdk.isOptedIn() // Returns a boolean
IMPORTANT! If user is not opted in start
method throws an error so you should wrap it's call inside of a try
block.
Logging
To enable logging to console by default, you can set the enableLogging
option to true
when creating the SDK instance:
var sdk = new HgSdk({
apiKey: '<your-api-key>',
backgroundServiceId: '<background-service-id>',
applicationId: '<your-application-id>'
enableLogging: true,
});
This will log all SDK events to the console, including session start, stop, and heartbeat events. You can also customize the logging by providing a custom logger function that takes a message as an argument. This allows you to log messages to a file or any other logging service of your choice.
var sdk = new HgSdk({
apiKey: '<your-api-key>',
backgroundServiceId: '<background-service-id>',
applicationId: '<your-application-id>'
enableLogging: true,
loggerCallback: function (message) {
// Custom logging logic
// For example, log to a file or send to a logging service
console.log(message);
}
});
Example log messages include:
info: Session started <session-id>
info: Heartbeat received
info: Heartbeat sent
info: Session stopped
error: Unable to resolve host
error: Unable to connect to server
Conclusion
After completing these steps you should have successful integration of the Honeygain Tizen SDK in your application.
If you'd still encounter any issues or have questions, you can always reach out to us at [email protected] for additional support.