Apptentive.Android 5.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Apptentive.Android --version 5.0.0
NuGet\Install-Package Apptentive.Android -Version 5.0.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Apptentive.Android" Version="5.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Apptentive.Android --version 5.0.0
#r "nuget: Apptentive.Android, 5.0.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Apptentive.Android as a Cake Addin
#addin nuget:?package=Apptentive.Android&version=5.0.0

// Install Apptentive.Android as a Cake Tool
#tool nuget:?package=Apptentive.Android&version=5.0.0

Apptentive Xamarin Android SDK

Register Apptentive

Register Apptentive in your Application class.

using System;
using Android.App;
using Android.Runtime;
using ApptentiveSDK.Android;

namespace ApptentiveSample
{
    [Application]
    public class MyApplication : Application
    {
        public MyApplication(IntPtr handle, JniHandleOwnership ownerShip)
            : base(handle, ownerShip)
        {
        }

        public override void OnCreate()
        {
            base.OnCreate();
            Apptentive.Register(this, "Your Apptentive Key", "Your Apptentive Signature");
        }
    }

}

Make sure you use the Apptentive App Key and Signature for the Android app you created in the Apptentive console. Sharing these keys between two apps, or using keys from the wrong platform is not supported, and will lead to incorrect behavior. You can find them here.

Message Center

See: How to Use Message Center

Showing Message Center

Add Message Center to talk to your customers.

var messageCenterButton = FindViewById<Button>(...);
messageCenterButton.Click += delegate
{
    Apptentive.ShowMessageCenter(context, (shown) => Console.WriteLine("Message Center shown: " + shown));
};

Checking Unread Message Count

You can also check to see how many messages are waiting to be read in the customer’s Message Center.

var unreadMessageCount = Apptentive.UnreadMessageCount;
if (unreadMessageCount > 0)
{
    Console.WriteLine("You have {0} unread messages", unreadMessageCount);
}

Unread Message Count Notification

public class MainActivity : Activity, IUnreadMessagesListener
{
    TextView unreadMessagesTextView;

    protected override void OnCreate(Bundle savedInstanceState)
    {
        base.OnCreate(savedInstanceState);
        
        ...

        unreadMessagesTextView = FindViewById<TextView>(...);

        Apptentive.AddUnreadMessagesListener(this);
    }

    public void OnUnreadMessageCountChanged(int count)
    {
        RunOnUiThread(delegate ()
        {
            unreadMessagesTextView.Text = "Unread messages: " + Apptentive.UnreadMessageCount;
        });
    }
}

The listener will not be run on the UI thread, and may be called from a different Activity than the one that is set on the listener. The correct way of setting Apptentive listeners is to create a listener with the same lifecycle as it’s intended usage, then passing it to Apptentive. For example, if the listener is going to be used in a specific activity, make the listener an Activity data member. This way, when the activity is gone, the listener will automatically be garbage collected and Apptentive will know about this through WeakReference (and we’ll stop calling the listener).

Events

Events record user interaction. You can use them to determine if and when an Interaction will be shown to your customer. You will use these Events later to target Interactions, and to determine whether an Interaction can be shown. You trigger an Event with the Engage() method. This will record the Event, and then check to see if any Interactions targeted to that Event are allowed to be displayed, based on the logic you set up in the Apptentive Dashboard.

var engageButton = FindViewById<Button>(...);
engageButton.Click += delegate
{
    Apptentive.Engage(this, "my_event", (engaged) => Console.WriteLine("Interaction engaged: " + engaged));
};

You can add an Event almost anywhere in your app, just remember that if you want to show an Interaction at that Event, it needs to be a place where launching an Activity will not cause a problem in your app.

Push Notifications

Apptentive can send push notifications to ensure your customers see your replies to their feedback in Message Center.

Firebase Cloud Messaging

If you are using Firebase Cloud Messaging (FCM) directly, without another push provider layered on top, please follow these instructions.

using System;
using Android.App;
using Firebase.Iid;
using Android.Util;
using ApptentiveSDK.Android;

namespace ApptentiveSample
{
    [Service]
    [IntentFilter(new[] { "com.google.firebase.INSTANCE_ID_EVENT" })]
    public class MyFirebaseIIDService : FirebaseInstanceIdService
    {
        const string TAG = "MyFirebaseIIDService";
        public override void OnTokenRefresh()
        {
            var refreshedToken = FirebaseInstanceId.Instance.Token;
            Log.Debug(TAG, "Refreshed token: " + refreshedToken);
            Apptentive.SetPushNotificationIntegration(Apptentive.PushProviderApptentive, refreshedToken);
        }
    }
}
  • In your FirebaseMessagingService, get the title, body, and PendingIntent from the incoming push, and create a Notification to display to your customer. If the returned PendingIntent is null, then the push did not come from Apptentive, and you should handle it yourself.
using System;
using Android.App;
using Android.Content;
using Android.Media;
using Android.Support.V4.App;
using Android.Util;
using ApptentiveSDK.Android;
using Firebase.Messaging;

namespace ApptentiveSample
{
    [Service]
    [IntentFilter(new[] { "com.google.firebase.MESSAGING_EVENT" })]
    public class MyFirebaseMessagingService : FirebaseMessagingService
    {
        const string TAG = "MyFirebaseMsgService";

        /**
         * Called when message is received.
         */

        public override void OnMessageReceived(RemoteMessage message)
        {
            var data = message.Data;

            if (Apptentive.IsApptentivePushNotification(data))
            {
                Log.Error(TAG, "Apptentive push.");
                var title = Apptentive.GetTitleFromApptentivePush(data);
                var body = Apptentive.GetBodyFromApptentivePush(data);
                Apptentive.BuildPendingIntentFromPushNotification((pendingIntent) =>
                {
                    // This push is from Apptentive, but not for the active conversation, so we can't safely display it.
                    if (pendingIntent == null)
                    {
                        Log.Error(TAG, "Push notification was not for the active conversation. Doing nothing.");
                        return;
                    }

                    var defaultSoundUri = RingtoneManager.GetDefaultUri(RingtoneType.Notification);
                	var notificationBuilder = new NotificationCompat.Builder(this)
                    	.SetSmallIcon(Resource.Drawable.apptentive_status_gear)
                    	.SetContentTitle(title)
                    	.SetContentText(body)
                    	.SetAutoCancel(true)
                    	.SetSound(defaultSoundUri)
                    	.SetContentIntent(pendingIntent);
                	var notificationManager = (NotificationManager)GetSystemService(Context.NotificationService);
                	notificationManager.Notify(0, notificationBuilder.Build());
                    
                }, data);
            }
            else
            {
                // Non-Apptentive push
            }
        }
    }
}
Product Compatible and additional computed target framework versions.
MonoAndroid monoandroid70 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
6.1.0 2,642 8/1/2023
6.0.2 167 7/6/2023
6.0.1 3,765 5/11/2023
6.0.0 232 5/3/2023
5.8.4 32,239 9/29/2022
5.8.3 7,200 3/23/2022
5.8.2 2,804 2/18/2022
5.8.1 431 2/17/2022
5.8.0 465 1/12/2022
5.7.1 1,475 8/26/2021
5.7.0 340 8/4/2021
5.6.5 384 7/28/2021
5.6.4 334 7/7/2021
5.6.3 370 2/4/2021
5.6.2 5,731 1/13/2021
5.6.1 962 12/7/2020
5.6.0 773 9/28/2020
5.5.4 2,403 9/8/2020
5.5.3 727 6/1/2020
5.4.2 11,771 5/14/2019
5.4.0 9,267 1/29/2019
5.3.2 703 12/6/2018
5.3.1 718 10/29/2018
5.3.0 765 10/19/2018
5.1.0 5,650 5/14/2018
5.0.0 1,107 1/23/2018
4.1.0 1,690 11/9/2017