小编ric*_*er1的帖子

.NET MAUI - “必须在主线程上调用权限请求”

我很困惑,如果需要异步,我应该如何在 Android 应用程序的主线程上请求权限访问。我想在我的应用程序打开后立即执行此操作,但我收到以下错误:"Permission request must be invoked on main thread."我该如何执行此操作?我的理解是,这RequestAsync需要一个单独的线程(因为它是一个异步方法调用)。

public partial class SplashPage : ContentPage
{
    PermissionStatus LocationPermission;

    public SplashPage()
    {
        InitializeComponent();
        LocationPermission = PermissionStatus.Unknown;
    }

    protected override void OnAppearing()
    {
        var result = Task.Run(async () => await CheckLocationPermission());
        result.Wait();
        var resultval = result.Result;

        result = Task.Run(async () => await RequestLocationPermission());
        result.Wait();
    }

    public async Task<PermissionStatus> CheckLocationPermission()
    {
        LocationPermission = await Permissions.CheckStatusAsync<Permissions.LocationWhenInUse>();
        return LocationPermission;
    }

    public async Task<PermissionStatus> RequestLocationPermission()
    {
        try
        {
            if (LocationPermission == …
Run Code Online (Sandbox Code Playgroud)

c# android maui

3
推荐指数
1
解决办法
1834
查看次数

在 kotlin 中创建列表列表?

如何创建列表列表?

我有一个可变的整数列表:

val rsrpList = mutableListOf<Int>()
Run Code Online (Sandbox Code Playgroud)

现在我正在尝试创建一个列表列表,如下所示:

val rsrpList = mutableListOf<Int>()
val rsrqList = mutableListOf<Int>()
val levelList = mutableListOf<Int>()

val listoflists = List<List<Int>>
listoflists.add(rsrpList)
listoflists.add(rsrqList)
listoflists.add(levelList)
Run Code Online (Sandbox Code Playgroud)

但我知道这是错误的,因为我一次添加一个列表,而不是列表列表。我该怎么做?

kotlin

2
推荐指数
1
解决办法
6339
查看次数

.NET MAUI - 为什么绑定不能与 ObservableCollection 一起使用?

我有一个类“CellularInfo”,我试图在可观察集合中显示项目,但RssiRsrp、 和的绑定Rsrq未显示。

我知道 LTEInfo 正在 CellularInfo.xaml.cs 中填充,但它没有绑定。

蜂窝信息.xaml:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:local="clr-namespace:CellularSignal1"
             x:Class="CellularSignal1.CellularInfo"
             Title="Signal">
    <VerticalStackLayout>
        <ListView BackgroundColor="Red" ItemsSource="{x:Reference lteStrengths}">
            <ListView.ItemTemplate>
                <DataTemplate>
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition/>
                            <RowDefinition/>
                            <RowDefinition/>
                        </Grid.RowDefinitions>

                        <Label Grid.Row="0" Text="{Binding Rssi}" HeightRequest="50"/>
                        <Label Grid.Row="1" Text="{Binding Rsrp}" HeightRequest="50"/>
                        <Label Grid.Row="2" Text="{Binding Rsrq}" HeightRequest="50"/>
                    </Grid>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>
    </VerticalStackLayout>
</ContentPage>
Run Code Online (Sandbox Code Playgroud)

CellularInfo.xaml.cs:

namespace CellularSignal1;

using Android.Content;
using Android.OS;
using Android.Telephony;
using Java.Util.Logging;
using Microsoft.Maui.Controls;
using Microsoft.Maui.Controls.Internals;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;

public …
Run Code Online (Sandbox Code Playgroud)

.net c# xaml maui

2
推荐指数
1
解决办法
1020
查看次数

标签 统计

c# ×2

maui ×2

.net ×1

android ×1

kotlin ×1

xaml ×1