Skip to content

Commit

Permalink
Release 4.2.1 (#18)
Browse files Browse the repository at this point in the history
* 4.2.0 Release Jar added

* Release-4.2.1

This release contains bug fixes related to timing issue when Collections were not started if the User did not switch Activities in an application. Additional documentation for multiple platforms and hybrids available at support.kount.com.

Co-authored-by: Greg Davis <[email protected]>
Co-authored-by: jyothi.hv <[email protected]>
  • Loading branch information
3 people authored Nov 30, 2021
1 parent 861c337 commit 0f5384c
Show file tree
Hide file tree
Showing 8 changed files with 113 additions and 46 deletions.
7 changes: 4 additions & 3 deletions CheckoutExample/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ dependencies {
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.instantapps:instantapps:1.1.0'

implementation 'com.google.android.instantapps:instantapps:1.1.0'
implementation 'com.google.code.gson:gson:2.8.6'
implementation group: 'com.android.volley', name: 'volley', version: '1.2.0'
implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.4.10'
implementation "com.google.android.material:material:1.4.0-beta01"
implementation group: 'com.android.volley', name: 'volley', version: '1.2.1'
implementation "com.google.android.material:material:1.4.0"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"

}
2 changes: 1 addition & 1 deletion CheckoutExample/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />

<application
android:name="com.kount.api.analytics.AnalyticsApplication"
android:name="com.kount.api.analytics.KountAnalyticsApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.kount.checkoutexample;

import android.Manifest;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Build;
Expand All @@ -9,35 +10,65 @@
import android.widget.Button;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;

import com.kount.api.analytics.AnalyticsCollector;

import java.util.Locale;
import java.util.UUID;

public class MainActivity extends AppCompatActivity {
public class MainActivity extends AppCompatActivity implements ActivityCompat.OnRequestPermissionsResultCallback {

final int PERMISSIONS_REQUEST_LOCATION = 0;
static final int MERCHANT_ID = 999999; // Insert your valid merchant ID
static final int ENVIRONMENT = AnalyticsCollector.ENVIRONMENT_TEST;//For production need to add AnalyticsCollector.ENVIRONMENT_PRODUCTION
static String deviceSessionID = "";
private String KEY_UUID = "UUID";


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setTitle("Sample");
initView();

// Check for location permissions so the Data Collector can gather the device location
requestLocationPermissions();

//required section
AnalyticsCollector.setMerchantId(MERCHANT_ID);
//end required section

// This turns the alpha collections on(true)/off(false). It defaults to true
AnalyticsCollector.collectAnalytics(true);

// For production you need to add AnalyticsCollector.ENVIRONMENT_PRODUCTION
AnalyticsCollector.setEnvironment(ENVIRONMENT);

//Optional SessionID section
/** If you want to pass in a self generated sessionID(or one given to you by your servers)
* you can set it using colde like this. Otherwise the AnalyticsCollector will generate one
* for you.Make sure you set session id only one time in a user session.
* To do so set your sessionID below.*/
if (savedInstanceState == null) {
deviceSessionID = UUID.randomUUID().toString();
AnalyticsCollector.setSessionId(deviceSessionID);
} else {
deviceSessionID = savedInstanceState.getString(KEY_UUID);
AnalyticsCollector.setSessionId(deviceSessionID);
}
// END OPTIONAL SESSION_ID SECTION

//Request location permission for Android 6.0 & above
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
requestLocationPermissions(this);
else
AnalyticsCollector.collectDeviceDataForSession(this);


}

private void initView() {
final TextView merchant = (TextView) findViewById(R.id.merchant);
final TextView environment = (TextView) findViewById(R.id.environment);
final Button checkoutButton = (Button) findViewById(R.id.checkoutButton);
Expand All @@ -63,30 +94,28 @@ public void onClick(View v) {
});
}

void requestLocationPermissions() {
void requestLocationPermissions(Activity activity) {
final TextView location = (TextView) findViewById(R.id.location);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.ACCESS_FINE_LOCATION)) {
ActivityCompat.requestPermissions(this, new String[]{
Manifest.permission.ACCESS_FINE_LOCATION}, PERMISSIONS_REQUEST_LOCATION);
} else {
ActivityCompat.requestPermissions(this, new String[]{
Manifest.permission.ACCESS_FINE_LOCATION}, PERMISSIONS_REQUEST_LOCATION);
}

if (ContextCompat.checkSelfPermission(activity, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.ACCESS_FINE_LOCATION)) {
ActivityCompat.requestPermissions(activity, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, AnalyticsCollector.REQUEST_PERMISSION_LOCATION);
} else {
location.setText("Allowed");
ActivityCompat.requestPermissions(activity, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, AnalyticsCollector.REQUEST_PERMISSION_LOCATION);
}
} else {
// The permissions are allowed by default if installed on a device with a OS less than M
//This block executes when permission is already granted.
AnalyticsCollector.collectDeviceDataForSession(activity);
location.setText("Allowed");
}
}

@Override
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
final TextView location = (TextView) findViewById(R.id.location);
if (requestCode == PERMISSIONS_REQUEST_LOCATION) {
if (requestCode == AnalyticsCollector.REQUEST_PERMISSION_LOCATION) {
//this block executes when a user grant/deny the permission
AnalyticsCollector.collectDeviceDataForSession(this);
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
location.setText("Allowed");
} else {
Expand All @@ -95,4 +124,10 @@ public void onRequestPermissionsResult(int requestCode, String permissions[], in
}
}

@Override
protected void onSaveInstanceState(@NonNull Bundle outState) {
super.onSaveInstanceState(outState);
outState.putString(KEY_UUID, deviceSessionID);
}

}
6 changes: 3 additions & 3 deletions CheckoutExample/kotlinexample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ dependencies {
testImplementation 'junit:junit:4.13'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
implementation 'com.google.android.instantapps:instantapps:1.1.0'

implementation 'com.google.android.instantapps:instantapps:1.1.0'
implementation 'com.google.code.gson:gson:2.8.6'
implementation group: 'com.android.volley', name: 'volley', version: '1.2.0'
implementation "com.google.android.material:material:1.4.0-beta01"
implementation group: 'com.android.volley', name: 'volley', version: '1.2.1'
implementation "com.google.android.material:material:1.4.0"
}
2 changes: 1 addition & 1 deletion CheckoutExample/kotlinexample/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />

<application
android:name="com.kount.api.analytics.AnalyticsApplication"
android:name="com.kount.api.analytics.KountAnalyticsApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.kount.checkoutexample.kotlin

import android.Manifest
import android.app.Activity
import android.content.Intent
import android.content.pm.PackageManager
import android.os.Build
Expand All @@ -10,11 +11,12 @@ import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat
import com.kount.api.analytics.AnalyticsCollector
import kotlinx.android.synthetic.main.activity_main.*
import java.util.*

class MainActivity : AppCompatActivity() {
private val PERMISSIONS_REQUEST_LOCATION = 0
class MainActivity : AppCompatActivity(), ActivityCompat.OnRequestPermissionsResultCallback {
private val ENVIRONMENT: Int = AnalyticsCollector.ENVIRONMENT_TEST//For production need to add AnalyticsCollector.ENVIRONMENT_PRODUCTION

var deviceSessionID: String? = ""
private val KEY_UUID = "UUID"

companion object Cons {
val MERCHANT_ID = 999999 // Insert your valid merchant ID
Expand All @@ -24,15 +26,40 @@ class MainActivity : AppCompatActivity() {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
title = "Sample"
initView()

// Check for location permissions so the Data Collector can gather the device location
requestLocationPermissions()

//required section
AnalyticsCollector.setMerchantId(MERCHANT_ID)
//This turns the alpha collections on(true)/off(false). It defaults to true
//end required section

// This turns the alpha collections on(true)/off(false). It defaults to true
AnalyticsCollector.collectAnalytics(true)

// For production you need to add AnalyticsCollector.ENVIRONMENT_PRODUCTION
AnalyticsCollector.setEnvironment(ENVIRONMENT)

//Optional SessionID section
/** If you want to pass in a self generated sessionID(or one given to you by your servers)
* you can set it using colde like this. Otherwise the AnalyticsCollector will generate one
* for you.Make sure you set session id only one time in a user session.
* To do so set your sessionID below. */
if (savedInstanceState == null) {
deviceSessionID = UUID.randomUUID().toString()
AnalyticsCollector.setSessionId(deviceSessionID!!)
} else {
deviceSessionID = savedInstanceState.getString(KEY_UUID)
AnalyticsCollector.setSessionId(deviceSessionID!!)
}
// END OPTIONAL SESSION_ID SECTION

//Request location permission for Android 6.0 & above
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
requestLocationPermissions(this)
else
AnalyticsCollector.collectDeviceDataForSession(this)
}

private fun initView() {
merchant.text = "$MERCHANT_ID"
when (ENVIRONMENT) {
AnalyticsCollector.ENVIRONMENT_TEST -> environment.text = "Test"
Expand All @@ -44,34 +71,38 @@ class MainActivity : AppCompatActivity() {
checkoutButton.setOnClickListener {
startActivity(Intent(this@MainActivity, CollectionActivity::class.java))
}

}

private fun requestLocationPermissions() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.ACCESS_FINE_LOCATION)) {
ActivityCompat.requestPermissions(this, arrayOf(
Manifest.permission.ACCESS_FINE_LOCATION), PERMISSIONS_REQUEST_LOCATION)
} else {
ActivityCompat.requestPermissions(this, arrayOf(
Manifest.permission.ACCESS_FINE_LOCATION), PERMISSIONS_REQUEST_LOCATION)
}
fun requestLocationPermissions(activity: Activity?) {
if (ContextCompat.checkSelfPermission(activity!!, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.ACCESS_FINE_LOCATION)) {
ActivityCompat.requestPermissions(activity, arrayOf(
Manifest.permission.ACCESS_FINE_LOCATION), AnalyticsCollector.REQUEST_PERMISSION_LOCATION)
} else {
location.text = "Allowed"
ActivityCompat.requestPermissions(activity, arrayOf(
Manifest.permission.ACCESS_FINE_LOCATION), AnalyticsCollector.REQUEST_PERMISSION_LOCATION)
}
} else {
//This block executes when permission is already granted.
AnalyticsCollector.collectDeviceDataForSession(activity)
location.text = "Allowed"
}
}

override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) {
if (requestCode == PERMISSIONS_REQUEST_LOCATION) {
if (requestCode == AnalyticsCollector.REQUEST_PERMISSION_LOCATION) {
//this block executes when a user grant/deny the permission
AnalyticsCollector.collectDeviceDataForSession(this)
if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
location.text = "Allowed"
} else {
location.text = "Denied"
}
}
}

override fun onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState)
outState.putString(KEY_UUID, deviceSessionID)
}
}
Binary file removed KountDataCollector/kount-data-collector-4.1.3.jar
Binary file not shown.
Binary file not shown.

0 comments on commit 0f5384c

Please sign in to comment.