Apptentive.Android
5.0.0
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
<PackageReference Include="Apptentive.Android" Version="5.0.0" />
paket add Apptentive.Android --version 5.0.0
#r "nuget: Apptentive.Android, 5.0.0"
// 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.
- Follow the FCM instructions to Set Up a Firebase Cloud Messaging Client App.
- Go to Integrations, choose Apptentive Push, and enter your FCM Server Key.
- In your
FirebaseInstanceIdService
, pass Apptentive your token.
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, andPendingIntent
from the incoming push, and create aNotification
to display to your customer. If the returnedPendingIntent
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 | Versions Compatible and additional computed target framework versions. |
---|---|
MonoAndroid | monoandroid70 is compatible. |
-
MonoAndroid 7.0
- Xamarin.Android.Support.Design (>= 25.4.0.2)
- Xamarin.Android.Support.v4 (>= 25.4.0.2)
- Xamarin.Android.Support.v7.AppCompat (>= 25.4.0.2)
- Xamarin.Android.Support.v7.CardView (>= 25.4.0.2)
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 | 5,381 | 8/1/2023 |
6.0.2 | 209 | 7/6/2023 |
6.0.1 | 3,861 | 5/11/2023 |
6.0.0 | 262 | 5/3/2023 |
5.8.4 | 35,979 | 9/29/2022 |
5.8.3 | 7,903 | 3/23/2022 |
5.8.2 | 2,844 | 2/18/2022 |
5.8.1 | 475 | 2/17/2022 |
5.8.0 | 504 | 1/12/2022 |
5.7.1 | 1,515 | 8/26/2021 |
5.7.0 | 378 | 8/4/2021 |
5.6.5 | 423 | 7/28/2021 |
5.6.4 | 371 | 7/7/2021 |
5.6.3 | 408 | 2/4/2021 |
5.6.2 | 5,755 | 1/13/2021 |
5.6.1 | 1,002 | 12/7/2020 |
5.6.0 | 805 | 9/28/2020 |
5.5.4 | 2,442 | 9/8/2020 |
5.5.3 | 766 | 6/1/2020 |
5.4.2 | 12,156 | 5/14/2019 |
5.4.0 | 9,300 | 1/29/2019 |
5.3.2 | 754 | 12/6/2018 |
5.3.1 | 766 | 10/29/2018 |
5.3.0 | 806 | 10/19/2018 |
5.1.0 | 5,674 | 5/14/2018 |
5.0.0 | 1,127 | 1/23/2018 |
4.1.0 | 1,728 | 11/9/2017 |