I use Xamarin Form to create an android application.
My code is:
Intent intent = Android.App.Application.Context.PackageManager.GetLaunchIntentForPackage("com.myapp.game_unity");
if (intent != null)
{
intent.AddFlags(ActivityFlags.NewTask);
intent.PutExtra("test_key", "test_val");
Android.App.Application.Context.StartActivity(intent);
}
else
{
intent = new Intent(Intent.ActionView);
intent.AddFlags(ActivityFlags.NewTask);
intent.SetData(Android.Net.Uri.Parse("market://details?id=com.myapp.game_unity"));
intent.PutExtra("test_key", "test_val");
Android.App.Application.Context.StartActivity(intent);
}
where I want to pass the parameter “test_val” to the game. The game starts, but I can’t get the parameter.
In the game, I try to get this parameter, but nothing works.
My code:
var intent = new AndroidJavaClass("android.content.Intent");
var extras = intent.Call<AndroidJavaObject>("getExtras");
var val = extras.Call<string> ("getString", "test_key");
How can I pass the parameter with android app to the unity game (android)?
Unity version: 2019.3.0f6