How to open an Android app with sent data?
Open an Android app and send data
var appPackageName = "xxx.yyy.zzzz"
PackageManager pm = Android.App.Application.Context.PackageManager;
Intent it = pm.GetLaunchIntentForPackage(appPackageName);
if (it != null)
{
it.PutExtra("data", someThing);
it.SetFlags(ActivityFlags.NewTask);
Android.App.Application.Context.StartActivity(it);
}
var appPackageName = "xxx.yyy.zzzz"
PackageManager pm = Android.App.Application.Context.PackageManager;
Intent it = pm.GetLaunchIntentForPackage(appPackageName);
if (it != null)
{
it.PutExtra("data", someThing);
it.SetFlags(ActivityFlags.NewTask);
Android.App.Application.Context.StartActivity(it);
}
var appPackageName = "xxx.yyy.zzzz" PackageManager pm = Android.App.Application.Context.PackageManager; Intent it = pm.GetLaunchIntentForPackage(appPackageName); if (it != null) { it.PutExtra("data", someThing); it.SetFlags(ActivityFlags.NewTask); Android.App.Application.Context.StartActivity(it); }
Android app is opened and get data
protected override void OnCreate(Bundle savedInstanceState)
{
...
var data = Intent.GetStringExtra("data");
if (data != null)
{
DataModel obj = JsonConvert.DeserializeObject<DataModel>(data);
}
}
protected override void OnCreate(Bundle savedInstanceState)
{
...
var data = Intent.GetStringExtra("data");
if (data != null)
{
DataModel obj = JsonConvert.DeserializeObject<DataModel>(data);
}
}
protected override void OnCreate(Bundle savedInstanceState) { ... var data = Intent.GetStringExtra("data"); if (data != null) { DataModel obj = JsonConvert.DeserializeObject<DataModel>(data); } }
Why can’t app be opened in Android 10, 11?
It’s because of Android background limitation
background-starts
It’s necessary to add this permission into AndroidManifest file, user needs to turn it on
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
Leave a Reply