Я использую следующий вспомогательный метод для открытия внешнего приложения в приложении для Android.Проблема с обработкой исключений в Xamarin - Android
using Android.Content;
namespace xyzab
{
public static class ExternalAppLauncher
{
#region Constants
const string FacebooUrlSchema = "fb://page/34530418978";
const string FacebookAppName = "com.facebook.katana";
const string TwitterUrlSchema = "twitter://user?id=1534530";
const string TwitterAppName = "com.twitter.android";
#endregion
#region Public Methods
/// <summary>
/// Method that Launches the pre-installed app
/// </summary>
/// <returns>The app.</returns>
/// <param name="launcher">Launcher.</param>
public static Intent LaunchApp (Launcher launcher)
{
Intent intent = null;
switch (launcher) {
case Launcher.Facebook:
try {
var uri = Android.Net.Uri.Parse (FacebooUrlSchema);
intent = new Intent (Intent.ActionView, uri);
} catch (ActivityNotFoundException) {
var uri = Android.Net.Uri.Parse ("market://details?id=" + FacebookAppName);
intent = new Intent (Intent.ActionView, uri);
}
break;
case Launcher.Twitter:
try {
var uri = Android.Net.Uri.Parse (TwitterUrlSchema);
intent = new Intent (Intent.ActionView, uri);
} catch (ActivityNotFoundException) {
var uri = Android.Net.Uri.Parse ("market://details?id=" + TwitterAppName);
intent = new Intent (Intent.ActionView, uri);
}
break;
}
return intent;
}
#endregion
}
}
Намерение за помощником является, если цель приложение уже установлено у меня есть, чтобы открыть приложение. В противном случае мне нужно открыть рынок.
Но вот моя проблема в том, что приложения нет в телефоне. Он метает a ActivityNotFoundException Но это не входит в мой блок catch catch.
Даже в вызывающем месте я добавил try catch. Это также не вызывает исключения. Что здесь не так.
void ABCD(object sender, EventArgs e)
{
try
{
var intent = ExternalAppLauncher.LaunchApp(Launcher.Twitter);
if (null != intent)
StartActivity(intent);
}
catch (Exception)
{
throw;
}
`