Stephen McCormick
Stephen McCormick

Reputation: 1796

Starting Xamarin Android App from Another Android App

As the title states I am trying to start an Android Xamarin app from another (native) Android app and the packageManager.queryIntentActivities query is failing. So I am probably doing something wrong on the either the Android app side, or more likely on the Xamarin side.

Here is the class definition on the Xamarin side:

using Android.OS;

namespace DeepLinkTest.Droid
{
    [Activity(Label = "DeepLinkTest", Icon = "@mipmap/icon", Theme = "@style/MainTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
    [IntentFilter(new[] { Android.Content.Intent.ActionView },
        DataScheme = "*",
        DataHost = "deeplinktest",
        DataPath = "MyAppDidComplete",
        Categories = new[] { Android.Content.Intent.CategoryDefault })]
    public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
    {
        protected override void OnCreate(Bundle savedInstanceState)
        {
            TabLayoutResource = Resource.Layout.Tabbar;
            ToolbarResource = Resource.Layout.Toolbar;

            base.OnCreate(savedInstanceState);
            global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
            LoadApplication(new App());
        }
    }
}

From what I have read the intent is places as shown above the MainActivity.

And here is the call I am making (an uri based call - maybe that is the problem?) in the native Android App:

            Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("deeplinktest://MyAppDidComplete/somedata"));
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            // Verify it resolves
            PackageManager packageManager = getPackageManager();
            List<ResolveInfo> activities = packageManager.queryIntentActivities(intent, 0);
            boolean isIntentSafe = activities.size() > 0;

            // Start an activity if it's safe
            if (isIntentSafe) {
                startActivity(intent);
            }

Upvotes: 1

Views: 267

Answers (1)

David Wasser
David Wasser

Reputation: 95646

You've confused the HOST and SCHEME of the URL. Your URL:

"deeplinktest://MyAppDidComplete/somedata"

breaks down as follows:

  • scheme: "deeplinktest"
  • host: "MyAppDidComplete"
  • path: "/somedata"

Your IntentFilter is set to match:

  • scheme = "*"
  • host = "deeplinktest"
  • path = "MyAppDidComplete"

You should modify the one or the other so that they match.

Upvotes: 1

Related Questions