Added specific try catch in Android launchApp to avoid the app crashing when trying to launch app package name that are not installed on the device. (#3092)
This commit is contained in:
parent
64775694e0
commit
f04ff7777a
|
@ -72,17 +72,28 @@ namespace Bit.Droid.Services
|
||||||
|
|
||||||
public bool LaunchApp(string appName)
|
public bool LaunchApp(string appName)
|
||||||
{
|
{
|
||||||
if ((int)Build.VERSION.SdkInt < 33)
|
try
|
||||||
|
{
|
||||||
|
if ((int)Build.VERSION.SdkInt < 33)
|
||||||
|
{
|
||||||
|
// API 33 required to avoid using wildcard app visibility or dangerous permissions
|
||||||
|
// https://developer.android.com/reference/android/content/pm/PackageManager#getLaunchIntentSenderForPackage(java.lang.String)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
var activity = Microsoft.Maui.ApplicationModel.Platform.CurrentActivity;
|
||||||
|
appName = appName.Replace("androidapp://", string.Empty);
|
||||||
|
var launchIntentSender = activity?.PackageManager?.GetLaunchIntentSenderForPackage(appName);
|
||||||
|
launchIntentSender?.SendIntent(activity, Result.Ok, null, null, null);
|
||||||
|
return launchIntentSender != null;
|
||||||
|
}
|
||||||
|
catch (IntentSender.SendIntentException)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
catch (Android.Util.AndroidException)
|
||||||
{
|
{
|
||||||
// API 33 required to avoid using wildcard app visibility or dangerous permissions
|
|
||||||
// https://developer.android.com/reference/android/content/pm/PackageManager#getLaunchIntentSenderForPackage(java.lang.String)
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
var activity = Microsoft.Maui.ApplicationModel.Platform.CurrentActivity;
|
|
||||||
appName = appName.Replace("androidapp://", string.Empty);
|
|
||||||
var launchIntentSender = activity?.PackageManager?.GetLaunchIntentSenderForPackage(appName);
|
|
||||||
launchIntentSender?.SendIntent(activity, Result.Ok, null, null, null);
|
|
||||||
return launchIntentSender != null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task ShowLoadingAsync(string text)
|
public async Task ShowLoadingAsync(string text)
|
||||||
|
|
Loading…
Reference in New Issue