小编Jud*_*ham的帖子

Xamarin 形式的 iOS 捆绑包 ID

如何在 Xamarin 表单应用程序中找到 iOS 的包 ID 和包名称?我可以在 Android 清单中找到 Android 的包名,但对 iOS 一无所知。

xamarin.ios xamarin.forms

15
推荐指数
3
解决办法
7677
查看次数

如何修复 GattStatus:3 - BLE Xamarin 表单应用程序的 WriteNotPermitted 异常?

我正在开发 BLE 应用程序。我能够连接到 MI 频段并通过我的 Xamarin 表单 BLE 应用程序获取服务。但是当我尝试编写特性时,我遇到了异常。我得到了例外

特性不支持写入。

为方法WriteAsync()。这是我写入特性的代码:

private async Task<string> ProcessDeviceInformationService(IService deviceInfoService)
    {
        try
        {
           await adapter.ConnectToDeviceAsync(device);
            var sb = new StringBuilder("Getting information from Device Information service: \n");
            var characteristics = await deviceInfoService.GetCharacteristicsAsync();
            var characteristic = await deviceInfoService.GetCharacteristicAsync(Guid.Parse("00002A27-0000-1000-8000-00805F9B34FB"));
           // characteristic.CanWrite = true;
            //foreach (var characteristic in characteristics)
            //{
                try
                {
                   // await Task.Delay(300);
                    var bytes = await characteristic.ReadAsync();
                    var str = Encoding.UTF8.GetString(bytes, 0, 0);
                    ManufacturerLabel.Text = str;
                    //var characteristic = await deviceInfoService.GetCharacteristicAsync(GattCharacteristicIdentifiers.DataExchange);
                    if (characteristic …
Run Code Online (Sandbox Code Playgroud)

c# bluetooth-lowenergy xamarin.forms bluetooth-gatt

7
推荐指数
1
解决办法
199
查看次数

BLE GATT 在连接后有时会断开连接并出现异常“GattCallback 错误:133”(xamarin 形式)

我正在以 Xamarin 形式实现 BLE。我能够执行所有 BLE 操作读取、写入和通知。但有时设备在连接后会断开连接。这是我得到的例外

Plugin.BLE.Abstractions.Exceptions.DeviceConnectionException: 'GattCallback 错误:133'

这是我进行连接的代码

 private async Task ScanForDevices(ScanData scanData)
        {
            
            _adapter = CrossBluetoothLE.Current.Adapter;
            _adapter.ScanMode = ScanMode.LowLatency;
            Device.BeginInvokeOnMainThread(async () =>
            {
                _adapter.DeviceDiscovered += async (s, a) =>
            {
                NativeDeviceAdd = DependencyService.Get<INativeDevice>().ConvertToNative(a.Device);
                PropertyInfo propInfo = NativeDeviceAdd.GetType().GetProperty("Name");
                BleDeviceName = (string)propInfo.GetValue(NativeDeviceAdd, null);
               
                string substr = scanData.blename;
                if (BleDeviceName == substr)
                {
                  
                     _device = a.Device;
                   
                   await _adapter.StopScanningForDevicesAsync();
                   await ConnectForDevice(_characteristicsBLE);

                }
            };
            });
            await _adapter.StartScanningForDevicesAsync();
        }


       
        private async Task ConnectForDevice(ICharacteristic characteristics)
        {
           
            await _adapter.ConnectToDeviceAsync(_device);
        }
Run Code Online (Sandbox Code Playgroud)

这些是日志。

01-08 17:31:50.435 D/BluetoothManager(26670): getConnectionState() …
Run Code Online (Sandbox Code Playgroud)

c# bluetooth-lowenergy xamarin.forms

5
推荐指数
2
解决办法
264
查看次数

如何在Xamarin表单后面的代码中获取BLE设备的mac地址?

我正在后台连接我的蓝牙 BLE 设备。因此,我需要在后面的代码中获取蓝牙 mac 地址,就像我们在 XAML 中显示 mac 地址一样。

ListView x:Name="lv" ItemSelected="lv_ItemSelected" BackgroundColor="White" SeparatorColor="Aqua"> 
                <ListView.ItemTemplate>
                    <DataTemplate>
                        <ViewCell>
                            <StackLayout>
                                <Label TextColor="Black" Text="{Binding NativeDevice.Address}"/>
                                <Label TextColor="Black" Text="{Binding NativeDevice.Name}"/>
                            </StackLayout>
                        </ViewCell>
                    </DataTemplate>
                </ListView.ItemTemplate>
            </ListView>
Run Code Online (Sandbox Code Playgroud)

所以在我们的 xaml 中,我能够在 NativeDevice.Address 中获取 mac 地址。因此,我需要以同样的方式将其放入我的 xaml.cs 中。我可以通过这种方法获取mac地址

var vailditems = adapter.DiscoveredDevices.Where(i => i.NativeDevice.ToString() 
Run Code Online (Sandbox Code Playgroud)

但这不是一个好方法,我需要像我的 xaml 一样获取 NativeDevice.Address 中的 mac 地址。我尝试了这种方法,但它给出的地址为空。

public class NativeDevice
        {
            
            public string Name { get; set; }
            public string Address { get; set; }
        }
NativeDevice V = new NativeDevice();

                    Baddress = V.Address; …
Run Code Online (Sandbox Code Playgroud)

c# bluetooth-lowenergy xamarin.forms

4
推荐指数
1
解决办法
2537
查看次数

有没有其他方法可以获取不会给我过时警告的 IMEI 号码?

嗨,我想在我的 Android 设备中获取IMEI 号码而我能够做到。但我收到过时警告说 ' TelephonyManager.DeviceId' is obsolete:'deprecated'。我正在使用此代码在我的 Android 设备中获取 IMEI 号码

Android.Telephony.TelephonyManager mTelephonyMgr;
        mTelephonyMgr = (Android.Telephony.TelephonyManager)Forms.Context.GetSystemService(Android.Content.Context.TelephonyService);

        return mTelephonyMgr.DeviceId;
Run Code Online (Sandbox Code Playgroud)

现在我可以通过使用禁用过时的警告

     mTelephonyMgr = (Android.Telephony.TelephonyManager)Forms.Context.GetSystemService(Android.Content.Context.TelephonyService);
#pragma warning disable CS0618 // Type or member is obsolete
            return mTelephonyMgr.DeviceId;
#pragma warning restore CS0618 // Type or member is obsolete
Run Code Online (Sandbox Code Playgroud)

但是为什么我会收到这个过时的警告?是否有不同的方法来获取 IMEI 号码,我不会收到这个过时的警告?

obsolete imei xamarin.forms

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