Comment on page
Getting Started
To get started with adding Firework Video components to your native Android project, the first step is to add the firework SDK and initialize it for usage.
- Firework App Id (Client id) - Contact Firework for this.
- Android Project Configuration
- JAVA_HOME 1.8
- minSdkVersion 21
- Minimum Kotlin Version 1.5.10
- compileSdkVersion 30
- targetSdkVersion 30
You can find the latest version of our SDK as well as the previous releases in the below link.
- 1.Add the following code snippet to your AndroidManifest.xml file <application><application>........//Activity needed for video playback<activity android:name="com.loopnow.fireworklibrary.PlaybackActivity" />// We plan on using advertising_id to improve target ads so that you can monetize better.// This is needed for to get advertising id using Android ad sdk.<meta-dataandroid:name="com.google.android.gms.ads.AD_MANAGER_APP"android:value="true" /></application>
- 2.Add the following code snippet to your project's build.gradle file allprojects {repositories {--------maven { url 'https://jitpack.io' }}}
- 3.Add the following code snippet to your application's build.gradle filedependencies {------ other dependencies------------implementation 'com.github.loopsocial:firework_sdk:{sdk_version}'// Note that you only need one based on the version you are using.// This is firework library based on play-services-ads to enable// admob advertisement.// Inlcude v20.0.0 version if you are using play-services v20.0.0// or above.implementation 'com.github.loopsocial:AndroidAdsService:v20.0.0'// Include if you are using play-service v19.5.0implementation 'com.github.loopsocial:AndroidAdsService:v19.5.0'// Include if you are using play-service v19.8.0implementation 'com.github.loopsocial:AndroidAdsService:v19.8.0'// If you do not include AndroidAdsService, you will miss on// monetizing video views.}android {..........dataBinding {enabled = true}compileOptions {sourceCompatibility 1.8targetCompatibility 1.8}}// Optional configurations.configurations.all {resolutionStrategy {force 'androidx.core:core-ktx:1.6.0'}resolutionStrategy {force 'androidx.core:core:1.6.0'}}
You can enable adding checksum to data reporting by adding the following snippet to AndroidManifest.xml
<Application>
<meta-data android:name="Firework:Checksum" android:value="true" />
</Application>Initialising Firework SDK
Before you begin using any of the features, you need to initialize the SDK. You should ideally do it in your application is created and is in the foreground.
Kotlin
Java
One way to know when your application is in foreground is to listen to activityLifecycleCallbacks
registerActivityLifecycleCallbacks(object: ActivityLifecycleCallbacks {
override fun onActivityCreated(p0: Activity, p1: Bundle?) {
}
override fun onActivityStarted(p0: Activity) {
++activityCounter
if(activityCounter == 1) {
initializeFireworkSDK() //Run your SDK Initialization inside this function
}
}
override fun onActivityResumed(p0: Activity) {
}
override fun onActivityPaused(p0: Activity) {
}
override fun onActivityStopped(p0: Activity) {
}
override fun onActivitySaveInstanceState(p0: Activity, p1: Bundle) {
}
override fun onActivityDestroyed(p0: Activity) {
}
})
}
You could also add the initialisation inside your Application class’ onCreate() method
/*
* Initializes FW SDK
* You must pass the clientId provided to you.
* Please contact Firework business team, if you don't have one.
* <p>
* This method will always return immediately and must be called on the main thread.
* It is recommended that you initialize FW SDK when application created. FW SDK must be initialized
* before using any of the features.
*
* @param applicationContext provide the application context. Do not pass the activity context.
* @param clientId client id received from Firework to be used with your application
* @param userId an id to uniquely identify device or user. If you don't have a unique id
* You can use Android_ID as it is or you can hash it and then use it.
* @param sdkStatusListener Callback used for reporting sdk status.
*
*
*/
FwSDK.initialize(this, clientId, userId, object : FwSDK.SdkStatusListener {
override fun currentStatus(status: SdkStatus, extra: String) {
Log.v("SdkStatusLog", "$status -> $extra " )
when(status) {
SdkStatus.Initialized -> {
Log.v("SdkStatusLog","Firework SDK Initialized");
}
}
}
})
The following methods are optional if you don't have a unique id for each user in your system
/**
* Firework SDK requires you pass the unique id for each of the users using
* your application. If you don't create a unque id for each user in your system
* you can use Android_ID. You can hash Android_ID in case there is any privacy concern.
* You can refer to the the function below to hash the Android_ID
*/
private val hashedUserId by lazy {
getHash(
Settings.Secure.getString(
applicationContext.contentResolver,
Settings.Secure.ANDROID_ID
))
}
/**
* returns the hashed value of the string text
* @param text string to be hashed
*/
private fun getHash(text: String) : String {
val digest: MessageDigest = MessageDigest.getInstance("SHA-256")
val hash: ByteArray = digest.digest(text.toByteArray(StandardCharsets.UTF_8))
Log.v("StatusLog", " ${text.length} and ${Base64.encodeToString(hash, Base64.DEFAULT).length} ")
return Base64.encodeToString(hash, Base64.DEFAULT)
}
Add this inside your Application class’ onCreate() method
/**
* Initializes FW SDK
* You must pass the clientId provided to you.
* Please contact Firework business team, if you don't have one.
* <p>
* This method will always return immediately and must be called on the main thread.
* It is recommended that you initialize FW SDK when application created. FW SDK must be initialized
* before using any of the features.
*
* @param applicationContext provide the application context. Do not pass the activity context.
* @param clientId client id received from Firework to be used with your application
* @param userId an id to uniquely identify device or user. If you don't have a unique id
* You can use Android_ID as it is or you can hash it and then use it.
* @param sdkStatusListener Callback used for reporting sdk status.
*
*
*/
FwSDK.initialize(this, clientId, userId, new FwSDK.SdkStatusListener() {
@Override
public void currentStatus(@NonNull SdkStatus sdkStatus, @NonNull String s) {
switch (sdkStatus){
case Initialized :
Log.v("FwDemo","Firework SDK Initialized");
break;
case InitializationFailed:
Log.v("FwDemo","Firework SDK Initialization Failed");
break;
case RefreshTokenFailed:
Log.v("FwDemo","Firework SDK Token Refresh Failed");
break;
}
}
});
The following methods are optional if you don't have a unique id for each user in your system
/**
* Firework SDK requires you pass the unique id for each of the users using
* your application. If you don't create a unique id for each user in your system
* you can use Android_ID. You can hash Android_ID in case there is any privacy concern.
* You can refer to the the function below to hash the Android_ID
*/
private String hashedUserId () {
return getHash(Settings.Secure.getString(getApplicationContext().getContentResolver(),Settings.Secure.ANDROID_ID));
}
/**
* returns the hashed value of the string text
* @param text string to be hashed
*/
private String getHash(String text) {
try {
MessageDigest digest = MessageDigest.getInstance("SHA-256");
byte[] hash = digest.digest(text.getBytes(StandardCharsets.UTF_8));
return Base64.encodeToString(hash,Base64.DEFAULT);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
Log.v("FwDemo","Android Id Hashing Failed");
return text;
}
}
Last modified 1yr ago