Exemple #1
0
        public async Task <CountlyResponse> ReportPushActionAsync()
        {
            string mesageId   = _bridge.MessageId;
            string identifier = _bridge.ButtonIndex;

            if (_bridge.MessageId != null)
            {
                var segment =
                    new Plugins.CountlySDK.Services.PushCountlyService.PushActionSegment
                {
                    MessageID  = mesageId,
                    Identifier = identifier
                };

                if (_config.EnableConsoleLogging)
                {
                    Debug.Log("[Countly] ReportPushActionAsync key: " + CountlyEventModel.PushActionEvent + ", segments: " + segment);
                }

                await _eventCountlyService.ReportCustomEventAsync(
                    CountlyEventModel.PushActionEvent, segment.ToDictionary());
            }

            _bridge.MessageId   = null;
            _bridge.ButtonIndex = null;

            return(new CountlyResponse
            {
                IsSuccess = true,
            });
        }
        public async Task <CountlyResponse> ReportPushActionAsync()
        {
            AndroidJavaClass store = new AndroidJavaClass(StorePackageName);

            bool isInitialized = store.CallStatic <bool>("isInitialized");

            if (!isInitialized)
            {
                AndroidJavaClass  unityPlayer        = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
                AndroidJavaObject activity           = unityPlayer.GetStatic <AndroidJavaObject>("currentActivity");
                AndroidJavaObject applicationContext = activity.Call <AndroidJavaObject>("getApplicationContext");

                store.CallStatic("init", applicationContext);
            }

            string data = store.CallStatic <string>("getMessagesData");

            if (string.IsNullOrEmpty(data))
            {
                return(new CountlyResponse
                {
                    IsSuccess = false,
                    ErrorMessage = "Key is required."
                });
            }

            JArray jArray = JArray.Parse(data);

            if (jArray != null)
            {
                foreach (JObject item in jArray)
                {
                    string mesageId   = item.GetValue("messageId").ToString();
                    string identifier = item.GetValue("action_index").ToString();

                    var segment =
                        new Plugins.CountlySDK.Services.PushCountlyService.PushActionSegment
                    {
                        MessageID  = mesageId,
                        Identifier = identifier
                    };

                    if (_config.EnableConsoleLogging)
                    {
                        Debug.Log("[Countly] ReportPushActionAsync key: " + CountlyEventModel.PushActionEvent + ", segments: " + segment);
                    }

                    await _eventCountlyService.ReportCustomEventAsync(
                        CountlyEventModel.PushActionEvent, segment.ToDictionary());
                }

                store.CallStatic("clearMessagesData");
            }

            return(new CountlyResponse
            {
                IsSuccess = true,
            });
        }