Copied To Clipboard

Xamarin


Integration

Import the NotifyVisitors SDK in your project

  1. Download the SDK from the link given below. You can also check our sample project for the reference.
  2. Download SDK Sample App Demo APK

    Extract the notifyvisitors.zip file ,open notifyvisitors/dll folder and copy Notifyvisitors.dll and add it as a reference to your app

  3. Copy all icons from notifyvisitors/drawables folder into Your Application’s Resources/drawables folder.
  4. Copy all files from notifyvisitors/anim folder into Your Application’s Resources/anim folder.
  5. Copy notifyvisitors/values/Ids.xml file into YourApplication's Resources/values folder.
  6. Copy the below strings and paste it into Your Application's Resources/values/Strings.xml file.
  • Strings 

        <string name ="menu_settings">settings</string>
        <string name ="title_activity_main">Push Notifications</string> 
        <string name ="error_config">Please set the %1$s constant and recompile the app.</string> 
        <string name ="already_registered">Device is already registered on server.</string> 
        <string name ="gcm_registered">From GCM: device successfully registered!</string> 
        <string name ="gcm_unregistered">From GCM: device successfully unregistered!</string> 
        <string name ="gcm_message">From GCM: you got message!</string> 
        <string name ="gcm_error">From GCM: error (%1$s).</string> 
        <string name ="gcm_recoverable_error">From GCM: recoverable error (%1$s).</string> 
        <string name ="gcm_deleted">From GCM: server deleted %1$d pending messages!</string> 
        <string name ="server_registering">Trying (attempt %1$d/%2$d) to register device on Demo Server.</string> 
        <string name ="server_registered">From Demo Server: successfully added device!</string> 
        <string name ="server_unregistered">From Demo Server: successfully removed device!</string> 
        <string name ="server_register_error">Could not register device on Demo Server after %1$d attempts.</string> 
        <string name ="server_unregister_error">Could not unregister device on Demo Server (%1$s).</string> 
        <string name ="options_register">Register</string> 
        <string name ="options_unregister">Unregister</string> 
        <string name ="options_clear">Clear</string> 
        <string name ="options_exit">Exit</string> 
        <string name ="dialog_fire_missiles">Notification</string> 
        <string name ="fire">See Notification</string>
        <string name ="cancel">No</string>

        <!--Start Notification Center Activity Content -->

        <!--Note:
          Followings are the string Values used in Notification Center Activity.
          You can change these values as per your requirement or as per our instruction -->

        <!-- start Notification Centre Activity Main View -->
        <string name ="nv_NC_ActivityBg">nv_default_bg</string>          <!--#e0e0e0 OR "name of drawable image" OR url of image(.png, .jpg, .jpeg) OR rgba(255,0,0,0.7)-->

        <!--Note:
        set a Color (must be 6 digit # Color) or Drawable Image name (must available in drawable folder) for the Background of Notification Center Activity Main View. -->
 
       <!--- end Notification Centre Activity Main View -->

       <!--- start Notification Centre Header Content -->
       <string name ="notifications_offers">Your latest updates and offers</string>
       <string name ="nv_headerTextStyle">normal</string>         <!-- (bold or italic or normal or bold-italic) -->
       <!--- end Notification  Header Content -->

       <!--- start Notification Centre Action Bar -->
       <string name ="nv_actionbarBackground">#ffffff</string> 

       <!--Note:
       set a Color (must be 6 digit # Color) or Drawable Image name (must available in drawable folder) or link (.jpg, .jpeg, .png) or rgba(255,0,0,0.7) for the Background of Notification Center Activity Actionbar Background. -->

       <string name ="nv_actionbarTitle">Notifications</string> 
       <string name ="nv_actionbarTitleStyle">bold</string>         <!-- (bold or italic or normal or bold-italic) -->
       <string name ="nv_actionbarCloseBtnImage">cross_nv_new</string>
       <!--- end Notification Centre Action Bar -->
       
       <!--- start Notification Centre Notifications List Content -->
       <string name ="nv_center_TitleTextStyle">bold</string>         <!-- (bold or italic or normal or bold-italic) -->
       <string name ="nv_center_push_DateStyle">normal</string>         <!-- (bold or italic or normal or bold-italic) -->
       <string name ="nv_center_push_MsgStyle">normal</string>         <!-- (bold or italic or normal or bold-italic) -->
       <string name ="nv_center_push_SummaryStyle">normal</string>         <!-- (bold or italic or normal or bold-italic) -->
       <string name ="nv_center_push_ctaStyle">bold</string>         <!-- (bold or italic or normal or bold-italic) -->
       <string name ="nv_monoImageName">sm_push_logo</string>
       <string name ="nv_fontAsset"></string>
       <string name ="message_copied">Message has been copied</string>
       <string name ="coupon_code_copied">Coupon Code has been copied</string>
       <string name ="coupon_code">Coupon Code : </string>
       <string name ="nv_center_removeIconName"></string>
       
       <!-- start Notification Centre No Notifications Content -->
       <string name ="nv_emptyImage">empty</string>         <!-- Empty Notification Image Drawable name -->
       <string name ="no_notifications">No New Notifications</string>
       <string name ="nv_noNotificationTextStyle">normal</string>         <!-- (bold or italic or normal or bold-italic) -->

       <!-- end Notification Centre No Notifications Content -->
       <string name ="nv_default_appicon">nvdefaulticon</string>

       <!-- End Notification Center Activity Content -->

        
  1. Copy notifyvisitors/values/Colors.xml file into Your Application's Resources/values folder.
  2. Copy notifyvisitors/values/Integers.xml file into Your Application's Resources/values folder.
  3. Copy all files from notifyvisitors/layout folder into Your Application's Resources/layout folder.
  4. Add following package referenceto your app:
    • Xamarin.GooglePlayServices.Base (version: 60.1142.1)

    • Xamarin.GooglePlayServices.Gcm (version: 60.1142.1)

    • Xamarin.GooglePlayServices.Location (version: 60.1142.1)

    • Xamarin.GooglePlayServices.Maps (version: 60.1142.1)

    • Xamarin.GooglePlayServices.SafetyNet (version: 60.1142.1)

    • Xamarin.GooglePlayServices.Ads (version: 60.1142.1)

    • Xamarin.Firebase.Config (version: 60.1142.1)

    • Xamarin.Firebase.Messaging (version: 60.1142.1)

    • Xamarin.Firebase.Analytics (version: 60.1142.1)

    • Xamarin.Firebase.Iid (version: 60.1142.1)

    • Xamarin.Android.Support.Design (version: 27.0.2.1)

    • Xamarin.Android.Support.v7.RecyclerView (version: 27.0.2.1)

    • Xamarin.Android.Support.v4 (version: 27.0.2.1)

    • Xamarin.Android.Support.v7.AppCompat (version: 27.0.2.1)

    • Xamarin.Android.Support.v7.CardView (version: 27.0.2.1)

Configure AndroidManifest.xml

Add permissions in AndroidManifest.xml file

IMPORTANT :

You need to replace your APPLICATION_ID in SMALL LETTERS wherever we use the following tag {YOUR_APPLICATION_ID} in the following integration steps.
  1. Insert the below XML snippet inside manifest <manifest> tag of your AndroidManifest.xml file
  • XML Snippet

        
            <uses-sdk android:minSdkVersion="15" />

            <uses-permission android:name="android.permission.INTERNET" /> 
            <uses-permission android:name="android.permission.GET_ACCOUNTS" />
            <uses-permission android:name="android.permission.GET_TASKS" />
            <uses-permission android:name="android.permission.WAKE_LOCK" />
            <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
            <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
            <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
            <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
            <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
            <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

            <permission android:name="{YOUR_APPLICATION_ID}.notifyvisitors.custom.PERMISSION" />
            <uses-permission android:name="{YOUR_APPLICATION_ID}.notifyvisitors.custom.PERMISSION" />
           <uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
           <!--for Samsung-->
           <uses-permission android:name="com.sec.android.provider.badge.permission.READ" />
           <uses-permission android:name="com.sec.android.provider.badge.permission.WRITE" />
           <!--for htc-->
           <uses-permission android:name="com.htc.launcher.permission.READ_SETTINGS" />
           <uses-permission android:name="com.htc.launcher.permission.UPDATE_SHORTCUT" />
           <!--for sony-->
           <uses-permission android:name="com.sonyericsson.home.permission.BROADCAST_BADGE" />
           <uses-permission android:name="com.sonymobile.home.permission.PROVIDER_INSERT_BADGE" />
           <!--for apex-->
           <uses-permission android:name="com.anddoes.launcher.permission.UPDATE_COUNT" />
           <!--for solid-->
           <uses-permission android:name="com.majeur.launcher.permission.UPDATE_BADGE" />
           <!--for huawei-->
           <uses-permission android:name="com.huawei.android.launcher.permission.CHANGE_BADGE" />
           <uses-permission android:name="com.huawei.android.launcher.permission.READ_SETTINGS" />
           <uses-permission android:name="com.huawei.android.launcher.permission.WRITE_SETTINGS" />
           <!--for ZUK-->
           <uses-permission android:name="android.permission.READ_APP_BADGE" />
           <!--for OPPO-->
           <uses-permission android:name="com.oppo.launcher.permission.READ_SETTINGS" />
           <uses-permission android:name="com.oppo.launcher.permission.WRITE_SETTINGS" />
        
        
  1. Insert the below XML snippet inside application <application> tag of your AndroidManifest.xml file
  • XML Snippet

        
        <application android:supportsRtl="true">

        <activity android:name = "com.notifyvisitors.notifyvisitors.FullScreenPopup" android:label = "@string/app_name" android:screenOrientation = "portrait"></activity>

        <activity android:name = "com.notifyvisitors.notifyvisitors.FullScreenPopupTranslucent" android:label = "@string/app_name" android:screenOrientation = "portrait" android:theme = "@android:style/Theme.Translucent.NoTitleBar.Fullscreen"></activity>

        <activity android:name = "com.notifyvisitors.notifyvisitors.TempActivity" android:theme = "@android:style/Theme.Holo.Light.Dialog"></activity>

        <activity android:name = "com.notifyvisitors.notifyvisitors.NotificationsListActivity" android:label = "@string/app_name" android:screenOrientation = "portrait"></activity>

        <receiver android:name = "com.notifyvisitors.notifyvisitors.PushGCMReceiver"  android:permission = "com.google.android.c2dm.permission.SEND">
            <intent-filter>
                <!-- Receives the actual messages. -->
                <action android:name = "com.google.android.c2dm.intent.RECEIVE"/>
                <!-- Receives the registration id. -->
                <action android:name = "com.notifyvisitors.nvsdklive" />
                <category android:name = "com.notifyvisitors.nvsdklive" />
            </intent-filter>
        </receiver>

        <receiver android:name = "com.notifyvisitors.notifyvisitors.NotifyVisitorsBroadcastReceiver" android:permission = "{YOUR_APPLICATION_ID}.notifyvisitors.custom.PERMISSION">
            <intent-filter>
                <action android:name = "com.android.vending.INSTALL_REFERRER" />
            </intent-filter>
        </receiver>

        <receiver android:name = "com.notifyvisitors.notifyvisitors.NVUnlockReceiver">
            <intent-filter>
                <action android:name = "android.intent.action.USER_PRESENT" />
                <action android:name = "android.intent.action.ACTION_SCREEN_ON" />
                <action android:name = "android.intent.action.ACTION_SHUTDOWN" />
            </intent-filter>
        </receiver>

        <receiver android:name = "com.notifyvisitors.notifyvisitors.AppUpdateReceiver" android:permission = "{YOUR_APPLICATION_ID}.notifyvisitors.custom.PERMISSION">
            <intent-filter>
                <action android:name = "android.intent.action.MY_PACKAGE_REPLACED" />
            </intent-filter>
        </receiver>

        <receiver android:name = "com.notifyvisitors.notifyvisitors.StickyPushNotification$StickyPushCloseReceiver"  android:permission = "{YOUR_APPLICATION_ID}.notifyvisitors.custom.PERMISSION" />
           
        <service android:name = "com.notifyvisitors.notifyvisitors.PushGCMIntentService" />

        <service android:name = "com.notifyvisitors.notifyvisitors.CheckUpdateService"  android:permission = "{YOUR_APPLICATION_ID}.notifyvisitors.custom.PERMISSION"></service>
        
        <service android:name = "com.notifyvisitors.notifyvisitors.OpenUrlService"  android:permission = "{YOUR_APPLICATION_ID}.notifyvisitors.custom.PERMISSION"></service>
        
        <service android:name = "com.notifyvisitors.notifyvisitors.UpdateNotificationService" android:permission = "{YOUR_APPLICATION_ID}.notifyvisitors.custom.PERMISSION"></service>

        <service android:name = "com.notifyvisitors.notifyvisitors.GeofenceTransitionsIntentService"></service>

        <service android:name = "com.notifyvisitors.notifyvisitors.PushNotificationEventListener" android:permission = "{YOUR_APPLICATION_ID}.notifyvisitors.custom.PERMISSION" />

        <service android:name = "com.notifyvisitors.notifyvisitors.UpdateCrouselService"  android:permission = "{YOUR_APPLICATION_ID}.notifyvisitors.custom.PERMISSION" />
        
        
  1. Again inside application <application> tag of your AndroidManifest.xml file add your BrandID and Secret Key as follows

Note :

In below example Dummy Brand ID and Secret keys shown. Kindly login your account to see your credentials.
  • Meta data
     
            <meta-data android:name="notifyvisitors_bid" android:value="52X"></meta-data>
            <meta-data android:name="notifyvisitors_bid_e" android:value="768B370B0002A3DEE5E8CD991DA80A12"></meta-data>
        

Initialize the SDK

  1. Initialize the SDK from the onCreate method of your Application class.
  • Initialize SDK

        NotifyVisitorsApplication.register(this);
        

OR

If you don’t have your own application class, then you can register our application class in the manifest file.

  • Initialize SDK

        <application android:name="com.notifyvisitors.notifyvisitors.NotifyVisitorsApplication">
        

InApp Notifications

InApp Notifications include both Banners and Surveys. These are displayed based on Android Activity.

Every event occurs in the context of an Activity. Every activity can be associated with some contextual data, which can be used as targeting rules for In-App Notifications.

Call the below show() method in onCreate method of every activity. show() method should be called only once per activity.

  • InApp Notification

        NotifyVisitorsApi.GetInstance(this).Show(null,null,null);
        

Dynamic Tokens() - Dynamic tokens are used to show personalised content in Notification messages real time.

  • Dynamic Tokens

        JSONObject category = new JSONObject();
        try {
        category.Put("firstCategory","standard");
        category.Put("secondCategory","fancy");
        } catch (JSONException e) {
        e.PrintStackTrace();
        }   
        

Custom Rules() - This data can be used in configuring targeting rules for the Notifications.

  • Custom Rules

        JSONObject category = new JSONObject();
        try {
        category.Put("categoryID","101");
        category.Put("categoryName","shoes");
        } catch (JSONException e) {
        e.PrintStackTrace();
        }   
        

Fragment Name (string) - If you have multiple fragment tabs in your activity, you can call the show() method for each fragment and pass the fragment name as third argument.

Push Notifications

Configure Notification’s Icon

For below Lollipop (version 5.0) devices:- Devices below Lollipop (version 5.0) shows only one icon in the push notifications, that you can configure from notifyvisitors panel.
To change default notification icon, you can replace icon sm_push.png in Your Application's Resources/drawables folder.

For Lollipop (version 5.0) & above devices:- Devices supporting Lollipop (version 5.0) & above shows two notifications icon i.e., small push icon & large push icon.

Large push icon is configured from panel & is shown as main push icon. However if large push icon is not configured from panel then small push icon is shown as main push icon.Small push icon

Small push icon according to android documentation(https://developer.android.com/about/versions/android-5.0-changes.html) should be transparent, otherwise it will be shown as square white spot.
To change default notification icon, you can replace icon sm_push_logo.png into Your Application's Resources/drawables folder.

Notification Center

You can show a list of push notifications received in an In-app Notification Center. Expiry of the notifications can be set from the panel.

You can call the showNotifications() method to show Notification Center on any click action.

  • Show Notifications

        NotifyVisitorsApi.getInstance(this).showNotifications(0);   
        

Track Users

User API enables you to track a user's activity as they move from device to device and attach attributes to their profiles. Attributes enrich user profiles, like email, username, mobile, gender etc.
This method should be called when the user is identified (mostly on login).

  • Track Users

        NotifyVisitorsApi.GetInstance(getActivity()).UserIdentifier(String userID, jsonObject jsonObject);   
        

USER_ID - Setting the Unique ID is a critical piece to tie a user across devices and installs/uninstalls as well across all platforms (i.e. iOS, Android, Windows, The Web). Unique ID can be something like an email ID, a username (unique), or any Backend generated ID.

USER_ATTRIBUTES (JSON object) - You can set the user attributes like name, email, mobile number. These can then be used to send personalised content in notifications. But these attributes can not be used in segmenting the users.

Default Attribute Names -

  • name
  • email
  • mobile

You can also pass your custom attributes like username, birthday, first name, last name.

IMPORTANT :

Attribute Names should contain only alpha-numerics, white spaces or ‘_’ ;
No other special characters are allowed.
Recommended names - ‘first_name’, ‘last_name’

Sample Code

  • Track User Sample Code

        jsonObject userObject = new JSONObject();
        try {
            userObject.Put("name","Basant");
            userObject.Put("number","98987XXXXX");
        } catch (JSONException e) {
            e.PrintStackTrace();
        }
        NotifyVisitorsApi.GetInstance(getActivity()).UserIdentifier("yourUserID",userObject);
           
        

Track Events

Event API enables you to record any actions your users perform, along with any properties that describe the action. These are then used for analytics, user segmentation or to trigger engagements or other actions.

  • Track Events

        NotifyVisitorsApi.GetInstance(getActivity()).Event(String eventName, JSONArray attributes, String ltv, String scope);
        
        

EVENT_NAME (string) Name of the event like sale, register.
Event names should contain only alpha-numerics, white spaces or ‘_’ ; No other special characters are allowed.

EVENT_ATTRIBUTES (JSON Array) Attributes associated with the event.
Attribute values should be passed in the form of Javascript strings, booleans and numbers respectively. Similarly date attribute values are expected in the form of Javascript date objects.

IMPORTANT :

Attribute Names should contain only alpha-numerics, white spaces or ‘_’ ;
No other special characters are allowed.
Recommended names - ‘category’, ‘price_usd’

LIFETIME_VALUE (integer) The score you would like to reward the user on performing this event like 10, 100.

SCOPE (integer)The scope of the event, whether it should be tracked every time it is called, or per session, or once in a lifetime. This parameter is used to minimise the duplication of data in analytics.
It is an integer whose values are :

  1. Track every time the api is called
  2. Track once per session
  3. Track once in a lifetime

  • Track Events

       
       JSONObject eventAttributes = new JSONObject();
        try {
            eventAttributes.Put("price","20000");
            eventAttributes.Put("firstCategory","standard");
            eventAttributes.Put("secondCategory","fancy");
        } catch (JSONException e) {
            e.PrintStackTrace();
        }
        NotifyVisitorsApi.GetInstance(getActivity()).Event("eventName", eventAttributes, "7","2");