如何在电报中共享与我的android设备上安装的应用程序的深层链接?

时间:2019-01-19 15:40:13

标签: c# android xamarin xamarin.android telegram

我想与我的Android设备上安装的我自己的应用共享电报中的深层链接。

我创建了我的应用程序的注册(我的活动,应该打开),如下所示:

[Activity(Label = "@string/app_name", MainLauncher = true, Theme = "@style/Theme.Splash", NoHistory = true, ScreenOrientation = ScreenOrientation.Portrait)]
[IntentFilter(new[] { Intent.ActionView }, Categories = new[] {Intent.ActionView,Intent.CategoryDefault,Intent.CategoryBrowsable}, DataScheme = "todolist", DataHost = "my_code_is_here")]
    public class SplashScreen : MvxSplashScreenActivity
    {
        public SplashScreen()
            : base(Resource.Layout.SplashScreen)
        {
        }
    }

在那之后,我想确保自己做的一切正确。我创建了一个HTML文件,其代码如下所示:

<a href="todolist://my_code_is_here">This is an example</a>

我使用Google Chrome浏览器在Android设备上打开了此文件。当我单击它时显示一个链接,我的应用程序打开了!一切正常!

此后,在我的程序中,我创建了一种向Telegrams共享文本消息的方法,代码如下所示:

private string _shareText = "Hi, this is my message.";
private readonly string _dataMIMEType = "text/plain";
private readonly string _titleOfChooserIntent = "Share with";
private readonly string _appName = "org.telegram.messenger";
private Intent _actionSendIntent;
private Intent _chooserIntent;
public ImageButton TelegramShare;
public MyClass()
{
    TelegramShare = FindViewById<ImageButton>(Resource.Id.image_button_share);
    TelegramShare.Click += ShareEmailToTelegram;
}
private void ShareEmailToTelegram(object sender, EventArgs e)
{
    if (IsAppInstalled(_appName))//check whether Telegram is installed
    {
        _actionSendIntent = new Intent(Intent.ActionSend);
        _actionSendIntent.SetType(_dataMIMEType);
        _actionSendIntent.SetPackage(_appName);
        if (_actionSendIntent != null)
        {
            _actionSendIntent.PutExtra(Intent.ExtraText, _shareText);
            _chooserIntent = Intent.CreateChooser(_actionSendIntent, _titleOfChooserIntent);
            Application.Context.StartActivity(_chooserIntent);
            return;
        }
    }
    else
    {
        Toast.MakeText(Application.Context, "Telegram is not installed", ToastLength.Short).Show();
    }
}

通过单击按钮,一切正常,消息被发送到Telegram。

我插入Google链接而不是文字:

_shareText = "https://www.google.com";

将其发送到Telegram后,它是一个链接,当我单击它时,即会打开google.com。 但是当我插入到应用程序的链接而不是文本时:

_shareText = "todolist://my_code_is_here";

然后,只有文本被发送到Telegram,这不是链接!

我试图做这样的事情:

if (_actionSendIntent != null)
{
    var uri = new Uri("todolist://my_code_is_here");
    _actionSendIntent.PutExtra(Intent.ExtraText, uri);
    _chooserIntent = Intent.CreateChooser(_actionSendIntent, _titleOfChooserIntent);
    Application.Context.StartActivity(_chooserIntent);
    return;
}

像这样:

if (_actionSendIntent != null)
{
    string s = "<a href=\"" + "todolist://my_code_is_here\"" + ">This is an example</a>";
    _actionSendIntent.PutExtra(Intent.ExtraText, Html.FromHtml(s));
    _chooserIntent = Intent.CreateChooser(_actionSendIntent, _titleOfChooserIntent);
    Application.Context.StartActivity(_chooserIntent);
    return;
}

结果是一样的,它不是链接,只是文本!

请有人帮我找到答案!

提前谢谢!

0 个答案:

没有答案