【问题标题】:Is it possible to open another app in my app with xamarin.form?是否可以使用 xamarin.form 在我的应用程序中打开另一个应用程序?
【发布时间】:2019-02-03 08:47:17
【问题描述】:

我是频道的新人;我最近开始使用 xamarin.form 来开发跨平台应用程序。

我被一个问题困扰了几天。我想知道是否有一种方法可以让我通过我的应用程序打开第三方应用程序,或者是否需要以不同的方式为每个平台实现此功能。

确切地说,我想知道是否有类似于 UIWebview 中的 IFrame 提供的方法,用于在我的应用程序中打开第三方应用程序而不启动第二个应用程序在后台发送我的应用程序的网页?

【问题讨论】:

  • 您能否提供更具体的示例来说明您想要归档的内容?
  • 当然,想象一个主页,其中有 3 个按钮,每个按钮代表不同的应用程序(例如 facebook、twitter 和 instagram),当用户单击其中一个按钮时,我的应用程序应该打开在我的应用程序的新页面中选择的应用程序,我想在其中实现类似于网页 iframe 的方法(因此是一个可视框,只需启动第三个应用程序并使其对用户使用)。当用户按下 back_button 时,应用程序将返回主页面

标签: c# xamarin xamarin.forms cross-platform


【解决方案1】:

你可以试试这个;

 private async void Button_OnClicked(object sender, EventArgs e)
            {  //You need to change your app package address which you want to open with button. Example: "com.microsoft.office.officelens"
                Intent intent = new Intent();
                intent.SetComponent(new ComponentName("com.package.address", "com.package.address.MainActivity")); 
                Android.App.Application.Context.StartActivity(intent);
            }

另外,如果您想检查用户下载或未下载此应用;

public string facebookApp;



public async Task ShowAlert()
        {
            this.facebookApp = "https://play.google.com/store/apps/details?id=com.facebook.katana&hl=tr";
            var action = await DisplayAlert("Warning", "Please download facebook app first.", "Okay", "Cancel");
            if (action)
            {
                Device.OpenUri(new Uri(this.facebookApp));
            }
        }

private async void Button_OnClicked(object sender, EventArgs e)
           {  
                try
                {
                    Intent intent = new Intent();
                    intent.SetComponent(new ComponentName("com.package.address", "com.package.address.MainActivity")); 
                    Android.App.Application.Context.StartActivity(intent);
                }
                catch (Exception ex)
                {
                    ShowAlert();
                }
           }

所以,在这种情况下;如果用户之前没有下载过xApp(facebook、twitter等),他/她会收到警告。如果他们在 DisplayAlert 上点击 Okay,程序会将他们发送到 Google Play 链接。

【讨论】:

    猜你喜欢
    • 2021-08-20
    • 1970-01-01
    • 2011-03-21
    • 2011-10-06
    • 2012-03-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多