using System Collections using System Collections Generic using UnityE

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Unity.Notifications.Android;
public class AdController : MonoBehaviour
{
public static AdController instance;
AndroidNotificationCenter.NotificationReceivedCallback receivedNotificationHandler =
delegate(AndroidNotificationIntentData data)
{
Dictionary<string, object> extras = new Dictionary<string, object>();
extras.Add("id",data.Id);
extras.Add("Title",data.Notification.Title);
extras.Add("Body",data.Notification.Text);
Kochava.Event pushOpenEvent = new Kochava.Event (Kochava.EventType.PushOpened);
pushOpenEvent.payload = extras;
Kochava.Tracker.SendEvent (pushOpenEvent);
};
void Awake ()
{
if (instance == null){
instance = this;
DontDestroyOnLoad(transform.gameObject);
} else {
Destroy(transform.gameObject);
}
}
void Start(){
Kochava.Tracker.Initialize();
var c = new Unity.Notifications.Android.AndroidNotificationChannel()
{
Id = "MainChannel_id",
Name = "Default Channel",
Importance = Importance.High,
Description = "Generic notifications",
};
AndroidNotificationCenter.RegisterNotificationChannel(c);
AndroidNotificationCenter.OnNotificationReceived += receivedNotificationHandler;
}
public void OnTokenReceived(object sender, Firebase.Messaging.TokenReceivedEventArgs token) {
// Add the new/updated push token to Kochava.
Kochava.Tracker.AddPushToken (token.Token);
}
private void AppOpenFromNotification(Dictionary<string, object> extras, string deeplink) {
if (extras.ContainsKey ("kochava")) {
// This app launch was due to a Kochava Push.
// Send a Push Opened event containing the Kochava campaign information.
Kochava.Event pushOpenEvent = new Kochava.Event (Kochava.EventType.PushOpened);
pushOpenEvent.payload = extras;
Kochava.Tracker.SendEvent (pushOpenEvent);
var notification = new AndroidNotification();
notification.Title = "DEEPLink";
notification.Text = deeplink;
notification.FireTime = System.DateTime.Now.AddSeconds(5);
AndroidNotificationCenter.SendNotification(notification, "MainChannel_id");
// Handle the deeplink
// ...
}
}
public void OnMessageReceived(object sender, Firebase.Messaging.MessageReceivedEventArgs e) {
IDictionary<string, string> data = e.Message.Data;
// Retrieve our engagement campaign information.
string kochava;
data.TryGetValue ("kochava", out kochava);
if (kochava != null && data.ContainsKey("silent")) {
// This is a Kochava silent push. These are used for tracking uninstalls and should not be acted on.
} else if (kochava != null) {
//This is a regular Kochava push.
//Retrieve the rest of the items for our push.
string iconResourceId;
string title;
string message;
string link;
data.TryGetValue ("icon_resource_id", out iconResourceId);
data.TryGetValue ("title", out title);
data.TryGetValue ("message", out message);
data.TryGetValue ("link", out link);
var notification = new AndroidNotification();
notification.IntentData = "{\"title\": \"Notification 1\", \"data\": \"200\"}";
notification.Title = title;
notification.Text = message;
notification.FireTime = System.DateTime.Now.AddSeconds(5);
AndroidNotificationCenter.SendNotification(notification, "MainChannel_id");
}
}
}