如何使用 Xamarin.Essentials Launcher 将 Android 设置应用启动到您的应用设置?

编程入门 行业动态 更新时间:2024-10-16 02:31:12
本文介绍了如何使用 Xamarin.Essentials Launcher 将 Android 设置应用启动到您的应用设置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我正在使用 Xamarin.Forms 和 Xamarin.Essentials 开发适用于 Android 和 iOS 的应用程序.我希望能够在我的应用中提供一个按钮,将用户带到设备的设置"应用,然后进入我正在开发的这个应用的特定设置页面.

以前,这是使用依赖项服务调用特定于平台的代码来完成的.我相信使用 Xamarin.Essentials Launcher (

I am working on an app for Android and iOS using Xamarin.Forms along with Xamarin.Essentials. I'd like to be able to provide a button in my app that would take the user to the device's 'Settings' app, then into the specific settings page for this app I'm working on.

Previously, this has been done using a dependency service to call into platform-specific code. I believe one can accomplish this much more simply, and without any platform-specific code using the Xamarin.Essentials Launcher (Microsoft documentation here). I have figured out how to do this on iOS:

bool didOpenUri = await Xamarin.Essentials.Launcher.TryOpenAsync("app-settings:com.yourCompany.yourApp");

However, I have not been able to discover how to do this on Android. If anything is unclear, please let me know. Otherwise, any assistance is appreciated... Thanks very much!

解决方案

As I know, there are no URLs for Android Settings. The Launcher do not support it.

But, the Settings class provides action strings for the Settings app.

Settings Class: https://docs.microsoft/en-us/dotnet/api/android.provider.settings?view=xamarin-android-sdk-9

You could do this in Android:

StartActivity(new Intent(Settings.ActionSettings));

And use Dependency service to do that in Xamarin.Forms.

Dependency service: https://docs.microsoft/en-us/xamarin/xamarin-forms/app-fundamentals/dependency-service/introduction

Updated:

In Xamarin.Forms:

Create a interface:

 public interface IStartSetttings
 {
    void StartSettings();
 }

Implementation of Android:

[assembly: Dependency(typeof(StartSettings_Implementation))]
namespace XamarinDemo.Droid.DependencyService_Implementation
{
    class StartSettings_Implementation : MainActivity, IStartSetttings
    {
        public void StartSettings()
        {
            var intent = new Intent(Settings.ActionSettings);
            Forms.Context.StartActivity(intent);          

        }
    }
}

Usage in Xamarin.Forms:

 DependencyService.Get<IStartSetttings>().StartSettings();

Screenshot:

这篇关于如何使用 Xamarin.Essentials Launcher 将 Android 设置应用启动到您的应用设置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-24 17:40:32,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1068429.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:您的   如何使用   Xamarin   Essentials   Launcher

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!