Share data between Unity Project to Android Studio java code

Viewed 1308

I Export my unity project to the android studio using these steps:

https://forum.unity.com/threads/integration-unity-as-a-library-in-native-android-app.685240/

But I want to ask that is there any option that I can send data from my native android app Intent to unity scripts because I am making an online game and I need to transfer my tokens to unity.

I have saved the token in shared preferences using Encrypted SharedPreference library in the android studio, server required token to respond on request so I want the token from my android intent to unity script.

Or Is there any way in unity to decrypt this token.

Please help me I am stuck

1 Answers

My workaround will be to approach this problem as if you are using an android plugin for Unity.

So you can use any activity that inherits from UnityPlayerActivity, or create your own.

Then use the in-build method UnityPlayer.UnitySendMessage, passing as parameters the gameObjectName that will have the receiver script attached, the name of the receiver method inside the receiver script, and the data you want to handle, in your case, the token. something like: UnityPlayer.UnitySendMessage(gameObjectName, "OnResultMethodName", tokenString);

You can see an example of how to do that here: https://github.com/Unity-Technologies/uaal-example

Related