1

I want to link to my app from an e-mail. The Xamarin documentations describes how to link to an app:

http://developer.xamarin.com/recipes/cross-platform/app-links/app-links-android/

However, it does that by referring to an additional component (Rivets) and it focuses on linking by code:

Rivets.AppLinks.Navigator.Navigate("http://location/of/your/html/file.html");

and it requires to publish a page:

Publish this page somewhere on the internet, or at a location your Android app can reach.

This feels like a complex solution for a very simple problem. I want to link from an e-mail to my app in a way that just works, even if my website would not work and preferably without additional components. I tried to do that based on explanations that focus on Android Java applications. This https://stackoverflow.com/a/11526028 and this https://stackoverflow.com/a/2958870

I did not succeed for my Xamarin app. Here is my AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="AndroidLink.AndroidLink" android:versionCode="1" android:versionName="1.0">
    <uses-sdk />
    <application android:label="AndroidLink" android:icon="@drawable/Icon">
        <activity android:name=".MainActivity" android:exported="false">
            <intent-filter>
                <data android:scheme="http" android:host="twitter.com" />
                <action android:name="android.intent.action.VIEW" />
            </intent-filter>
        </activity>
    </application>
</manifest>

When I send myself an e-mail with the following content http://twitter.com/status/1234 and click on that link in the Gmail app, the browser is opened, instead of my App.

Hopefully, this problem is solvable with Xamarin Android. Please note that:

  1. I want to link from an e-mail to my app.
  2. I prefer a working solution, even if my website would be down.
  3. I prefer the browser not to be opened.

In case, it is relevant, here is my C# code:

public class MainActivity : Activity
{
    int count = 1;

    protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);

        // Set our view from the "main" layout resource
        SetContentView(Resource.Layout.Main);

        // Get our button from the layout resource,
        // and attach an event to it
        Button button = FindViewById<Button>(Resource.Id.MyButton);

        var data = Intent.Data;
        if (data != null)
        {
            var scheme = data.Scheme;
            var host = data.Host;
            var pathSegments = data.PathSegments;
            button.Text = pathSegments.Count.ToString();
        }

        button.Click += delegate { button.Text = string.Format("{0} clicks!", count++); };
    }
}
Community
  • 1
  • 1
Daan
  • 2,478
  • 3
  • 36
  • 76
  • When you add an Intent filter for URI scheme, Android will let you choose a default app. Are you sure you haven't selected an app for twitter.com? Try using a scheme or domain that is unique. – Kiliman May 31 '15 at 19:24
  • You also might want to consider using an IntentFilter attribute in your code instead of the manifest file. See http://androidapi.xamarin.com/?link=T%3aAndroid.App.IntentFilterAttribute%2f* – Kiliman May 31 '15 at 19:29
  • Thanks for your reply. I am sure I have not selected an app for twitter.com. The problem is also for other websites. – Daan May 31 '15 at 20:11
  • Same problem when adding IntentFilter in code, also for another website: [IntentFilter(new[] { Intent.ActionView }, DataHost = "geenstijl.nl", DataScheme = "http")] – Daan May 31 '15 at 20:36
  • Just tried: same problem for other schemes. – Daan May 31 '15 at 23:02
  • I have just tried the following `IntentFilter` in my app and it works just fine: `[IntentFilter(new[] { Intent.ActionView }, Categories = new[] { Intent.CategoryDefault }, DataScheme = "http", DataHost = "blog.ostebaronen.dk")]`. `Intent.Data` in `OnCreate` is poplulated with the entire URL. I just sent an SMS to myself with a URL which matches the DataHost. – Cheesebaron Jun 02 '15 at 12:27
  • @Daan did you find the solution for opening app through link from browser. – Vicky Jul 01 '15 at 05:32

0 Answers0