Last active
March 4, 2021 05:52
-
-
Save kayahanbaskeser/a925a37e0dbea6edae95179f90e8f964 to your computer and use it in GitHub Desktop.
PushKitManager.cs | Key-Value Pairs of Notification Message
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// To get key-value pairs of notification message, call this method on awake or start methods. | |
// https://developer.huawei.com/consumer/en/doc/development/HMSCore-Guides/android-client-dev-0000001050042041#EN-US_TOPIC_0000001078601368__section934442861712 | |
// https://github.com/EvilMindDevs/hms-unity-plugin | |
public void getIntentData() | |
{ | |
AndroidJavaClass UnityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); | |
AndroidJavaObject currentActivity = UnityPlayer.GetStatic<AndroidJavaObject>("currentActivity"); | |
AndroidJavaObject intent = currentActivity.Call<AndroidJavaObject>("getIntent"); | |
if (intent == null) return; | |
// Obtain the values for reporting events. | |
Debug.Log($"[Notification Message / Key-Value] _push_msgid / {intent.Call<string>("getStringExtra", "_push_msgid")}"); | |
Debug.Log($"[Notification Message / Key-Value] cmdType / {intent.Call<string>("getStringExtra", "_push_cmd_type")}"); | |
Debug.Log($"[Notification Message / Key-Value] notifyId / {intent.Call<int>("getIntExtra", "_push_notifyid", -1)}"); | |
// Obtain the values in data. | |
AndroidBundle androidBundle = (AndroidBundle) Activator.CreateInstance(typeof(AndroidBundle), intent.Call<AndroidJavaObject>("getExtras")); | |
Dictionary<string, object> keyValuePairs = new Dictionary<string, object>(); | |
AndroidJavaObject androidBundleKeySet = androidBundle.Bundle.Call<AndroidJavaObject>("keySet"); | |
if (androidBundleKeySet != null) | |
{ | |
var javaList = new AndroidJavaObject("java.util.ArrayList", androidBundleKeySet); | |
int size = javaList.Call<int>("size"); | |
for (int i = 0; i < size; i++) | |
{ | |
var element = javaList.Call<string>("get", i); | |
keyValuePairs.Add(element, androidBundle.Bundle.Call<string>("getString", element)); | |
} | |
} | |
foreach (var item in keyValuePairs) | |
{ | |
Debug.Log($"[Notification Message / Key-Value] {item.Key} / {item.Value}"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment