Skip to content

rodrigobressan/android-sdk2

 
 

Repository files navigation

Android - Neosurance SDK

Build Status Known Vulnerabilities Codacy Badge codecov

  • Collects info from device sensors and from the hosting app
  • Exchanges info with the AI engines
  • Sends the push notification
  • Displays a landing page
  • Displays the list of the purchased policies

Example

To run the example project, clone the repo, and build it.

Installation

NeosuranceSDK is available through jitpack. To install it, simply add the following line to your project:

  1. Add it in your root gradle file at the end of repositories:

    allprojects {
    	repositories {
    		...
    		maven { url 'https://jitpack.io' }
    	}
    }
  2. Then add the dependency in your application gradle file

    dependencies {
    	...
    	implementation 'com.github.neosurance:android-sdk2:2.0.3'
    }

Requirements

  1. Inside your AndroidManifest.xml be sure to have the following permissions:

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
    <uses-permission android:name="com.google.android.gms.permission.ACTIVITY_RECOGNITION" />
  2. Inside your AndroidManifest.xml be sure to have the following activity:

    <activity
    	android:name="eu.neosurance.sdk.NSRActivityWebView"
    	android:configChanges="orientation|screenSize|keyboardHidden"
    	android:screenOrientation="portrait"
    	android:theme="@style/AppTheme.NSRWebView" />
  3. Inside your values/styles.xml be sure to have the following style:

    <style name="AppTheme.NSRWebView">
    	<item name="windowNoTitle">true</item>
    	<item name="windowActionBar">false</item>
    	<item name="android:windowFullscreen">false</item>
    	<item name="android:windowContentOverlay">@null</item>
    </style>

Use

  1. setup

    Earlier in your application startup flow (tipically inside the onCreate method of your main activity) call the setup method using

    base_url: provided by us, used only if no securityDelegate is configured
    code: the community code provided by us
    secret_key: the community secret key provided by us
    dev_mode optional: [0|1] activate the developer mode, all the webView in your app will be inspectable
    ask_permission optional: [0|1] the SDK will use default dialogs to ask for the required permissions once in application life
    push_icon optional: [resource id] the icon used in notification, if none provided neosurance badge will be used

    JSONObject settings = new JSONObject();
    settings.put("base_url", "https://<provided base url>");
    settings.put("code", "<provided code>");
    settings.put("secret_key", "<provided secret_key>");
    settings.put("dev_mode", 1);
    settings.put("ask_permission", 0);
    settings.put("push_icon", R.drawable.pushIcon);
    NSR.getInstance(this).setup(settings);
  2. setSecurityDelegate optional

    If the communications must be secured using any policy.
    A securityDelegate implementing the following interface can be configured:

    public interface NSRSecurityDelegate {
    	void secureRequest(Context ctx, String endpoint, JSONObject payload, JSONObject headers, NSRSecurityResponse completionHandler) throws Exception;
    }

    It's mandatory that your securityDelegate implement the default constructor.

    Then use the setSecurityDelegate method

    NSR.getInstance(this).setSecurityDelegate(<yourSecurityDelegate>);
  3. setWorkFlowDelegate optional

    If the purchase workflow must be interrupted in order to perform user login or to perform payment.
    A workflowDelegate implementing the following interface must be configured:

    public interface NSRWorkflowDelegate {
    	boolean executeLogin(Context ctx, String url);
    	JSONObject executePayment(Context ctx, JSONObject payment, String url);
    }

    It's mandatory that your ** workflowDelegate** implement the default constructor.

    Then use the setWorkflowDelegate method

    NSR.getInstance(this).setWorkflowDelegate(<yourWorkflowDelegate>);

    when login or payment is performed you must call the methods loginExecuted and paymentExecuted to resume the workflow

    NSR.getInstance(this).loginExecuted(<theGivenUrl>);
    ...
    NSR.getInstance(this).paymentExecuted(<paymentTransactionInfo>,<theGivenUrl>);
  4. registerUser

    When the user is recognized by your application, register him in our SDK creating an NSRUser and using the registerUser method.
    The NSRUser has the following fields:

    code: the user code in your system (can be equals to the email)
    email: the email is the real primary key
    firstname optional
    lastname optional
    mobile optional
    fiscalCode optional
    gender optional
    birthday optional
    address optional
    zipCode optional
    city optional
    stateProvince optional
    country optional
    extra optional: will be shared with us
    locals optional: will not be exposed outside the device

    NSRUser user = new NSRUser();
    user.setEmail("jhon.doe@acme.com");
    user.setCode("jhon.doe@acme.com");
    user.setFirstName("Jhon");
    user.setLastName("Doe");
    NSR.getInstance(this).registerUser(user);
  5. forgetUser optional

    If you want propagate user logout to the SDK use the forgetUser method.
    Note that without user no tracking will be performed.

    NSR.getInstance(this). forgetUser();
  6. showApp optional

    Is possible to show the list of the purchased policies (communityApp) using the showApp methods

    NSR.getInstance(this).showApp();

    or

    JSONObject params = new JSONObject();
    params.put("page", "profiles");
    NSR.getInstance(this).showApp(params);
  7. showUrl optional

    If custom web views are needed the showUrl methods can be used

    NSR.getInstance(this).showUrl(url);

    or

    JSONObject params = new JSONObject();
    params.put("privacy", true);
    NSR.getInstance(this).showUrl(url, params);
  8. sendEvent optional

    The application can send explicit events to the system with sendEvent method

    JSONObject payload = new JSONObject();
    payload.put("latitude", latitude);
    payload.put("longitude", longitude);
    NSR.getInstance(this).sendEvent("position", payload);
  9. sendAction optional

    The application can send tracing information events to the system with sendAction method

    NSR.getInstance(this).sendAction("read", "xxxx123xxxx", "general condition read");

Author

info@neosurance.eu

License

NeosuranceSDK is available under the MIT license. See the LICENSE file for more info.

About

Collects info from device sensors and from the hosting app

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 98.1%
  • Other 1.9%