- Home /
Call Unity apk with Intent and read extras
I was trying to call a Unity apk the "standard" Android way, via an intent, and sending some extra data along.
I don't see anything in the src for NativeActivity - has anyone accomplished reading the Intent extras from Unity side?
Here's the code I was using, but no extras are returned (and yes, I'm sure I'm calling the intent with extras):
var UnityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
var currentActivity = UnityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
var intent = currentActivity.Call<AndroidJavaObject>("getIntent");
var cmd = intent.Call<string>("getStringExtra", "cmd");
((Trivia: I know this was working a few Unity versions back, then the ProxyActivity broke it (a custom Activity was needed), now we have only NativeActivity left and it should work again without plugin)
Come on, someone must have used proper intents for Unity...
Answer by grzunov · Jan 23, 2016 at 01:26 AM
A little late, but in case anyone is looking for a solution, this is how my code is working:
string arguments = "";
AndroidJavaClass UnityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
AndroidJavaObject currentActivity = UnityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
AndroidJavaObject intent = currentActivity.Call<AndroidJavaObject>("getIntent");
bool hasExtra = intent.Call<bool> ("hasExtra", "arguments");
if (hasExtra) {
AndroidJavaObject extras = intent.Call<AndroidJavaObject> ("getExtras");
arguments = extras.Call<string> ("getString", "arguments");
}
This doesn't seem to work with adb, any tips? adb shell am start -n "com.company.product/com.unity3d.player.UnityPlayer" --es "arguments" "1"
It seems UnityPlayer
activity isn't found :(
Answer by dev2605vyas · Jun 29, 2017 at 01:07 PM
Best reply on the Internet for Passing Intent from Android Activity to Unity Scene
Your answer
Follow this Question
Related Questions
APK size question 0 Answers
how to send text from html page to unity android app? 0 Answers
APK size 70 mb more then editor log 0 Answers
After installing the .APK I see the app icon twice 1 Answer
Why APK freezes at start of game level? 0 Answers