I want to access the device mac in xamarin ios? - xamarin

I want to access the device mac in xamarin ios but it always return 02:00:00:00:00:00.
if (netInterface.NetworkInterfaceType == NetworkInterfaceType.Wireless80211 ||
netInterface.NetworkInterfaceType == NetworkInterfaceType.Ethernet)
{
var address = netInterface.GetPhysicalAddress();
return BitConverter.ToString(address.GetAddressBytes());
}
}
return "000000000000";

Related

How to get service from the connected Bluetooth device in Xamarin forms in IOS

I am getting service null for the connected devices, I need characteristic to write in device.
The "ConnectToDevice" method is retuning true but service is returning null, even status of the device is showing connected.
Here is below sample code design.
public bool ConnectToDevice(Device device)
{
// Disconnect any previously connected peripheral
if (_connectedPeripheral != null)
{
_centralManager.CancelPeripheralConnection(_connectedPeripheral);
_connectedPeripheral = null;
}
// Find the CBPeripheral object for the selected device
_selectedPeripheral = _centralManager.RetrievePeripheralsWithIdentifiers(
new NSUuid(device.Address)).FirstOrDefault();
if (_selectedPeripheral != null)
{
// Connect to the peripheral
_centralManager.ConnectPeripheral(_selectedPeripheral);
_selectedPeripheral.DiscoverCharacteristics(null, _selectedPeripheral.Services[0]);
return true;
}
else
{
return false;
}
}

Getting native device information from BluetoothLE device

I'm using the Plugin.BLE nuget package in my Xamarin project to interrogate the BLE devices I have. It seems to be working fine, but there is an object returned as part of the overall device object when the found device event is triggered. The object is called NativeDevice.
Intellisense is showing that this is an object which can be manipulated on the platform which is what I am trying to do so I can store and handle within my mvvm framework.
The problem is that if I cast the object as a Device on the platform and store that in a var, the var is always null.
How am I supposed to get the values from the object on the platform so I can pass these back to my view model?
My code looks like this
(in the forms project)
adapter.DeviceDiscovered += (s, a) =>
{
var adList = new List<AdvertisingRecords>();
foreach (var r in a.Device.AdvertisementRecords)
{
adList.Add(new AdvertisingRecords { Data = r.Data, Type = (AdvertisingRecordType)r.Type });
}
var newbtd = new BluetoothDevice
{
AdvertisementRecords = adList,
NativeDevice = DependencyService.Get<INativeDevice>().ConvertToNative(a.Device.NativeDevice),
Name = a.Device.Name,
Rssi = a.Device.Rssi,
Id = a.Device.Id,
State = (BluetoothStates)a.Device.State
};
btd.Add(newbtd);
};
On the platform
[assembly: Xamarin.Forms.Dependency(typeof(NativeDeviceConverter))]
namespace MyApp.Droid.Injected
{
public class NativeDeviceConverter : INativeDevice
{
public NativeDevice ConvertToNative(object device)
{
var dev = device as Device;
if (dev != null)
return new NativeDevice { Name = !string.IsNullOrEmpty(dev.BluetoothDevice.Name) ? dev.BluetoothDevice.Name : string.Empty, Address = dev.BluetoothDevice.Address, Type = dev.BluetoothDevice.Type.ToString() };
else
return new NativeDevice();
}
}
}
NativeDevice is my abstracted class that I used within the VM
The Reason why device value null is that the type of a.Device.NativeDevice is not of Device type. It is NativeObject so for android it is of type BluetoothDevice and for ios, it is CBPeripheral.
As I understand from your code you want to pass a.Device which is in turn of type Device. So you just need to replace it this line
NativeDevice = DependencyService.Get<INativeDevice>().ConvertToNative(a.Device.NativeDevice)
with
NativeDevice = DependencyService.Get<INativeDevice>().ConvertToNative(a.Device)
Now you can use Device.BluethoothDevice in android.

Detect iPhone X with Appcelerator

I am using custom navbar for my project and I am using codes for ios 7 top margin as below;
var _IsIos7Plus = false;
if (Titanium.Platform.name == 'iPhone OS') {
var _Version = Titanium.Platform.version.split(".");
var _Major = parseInt(_Version[0], 10);
if (_Major >= 7) {
_IsIos7Plus = true;
}
}
Alloy.Globals.Ios7TopMargin = _IsIos7Plus == true ? 20 : 0;
But iPhone X simulator shows 20 blank. Is there any way to detect iPhone X?
If you upgrade your project firstly you should check
Default-Portrait-2436h#3x.png
Default-Landscape-2436h#3x.png
splash screens are exists
Than you can detect iPhoneX code as below;
var IsIphoneX = (Ti.Platform.displayCaps.platformWidth === 375 && Ti.Platform.displayCaps.platformHeight === 812 && Ti.Platform.displayCaps.logicalDensityFactor === 3);

How to get a comprehensive list of apps installed on wear device?

i'm trying to get a list of the applications installed on the wear device using
packageManager.getInstalledPackages(PackageManager.GET_PERMISSIONS);
But many apps are missing from that list (all motorola apps, SetAlarm, SetTimer,ShowAlarms)
Anybody know what i should do to get all of them ?
That's because these apps are intended to be launched only with voice.
Here is how I get them in Wear Mini Launcher:
try {
ApplicationInfo app = manager.getApplicationInfo("com.google.android.deskclock", 0);
String name = manager.getApplicationLabel(app).toString();
Intent intentAI = new Intent();
intentAI.setPackage(app.packageName);
List<ResolveInfo> listRI = manager.queryIntentActivities(intentAI, 0);
// Launchable app
if (listRI.size() > 0) {
for (ResolveInfo resolveInfo : listRI) {
if (name != null) {
//Do your stuff here
}
}
}
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}

How to get the Device Resolution in Wp7

I want to set some icons in my app according to device screen resolution like wxga or wvga. I saw in many links like App.Current.Host.Content.ScaleFactor or Application.Current.RootVisual.RenderSize. But I can only access App.Current.Host.Content.ActualWidth or Height. These always say as 480x800 even though I am running the app in wxga Device. How do i know the resolution correctly ?
Windows Phone 7 only supports one resolution(800*480). Are you asking about Windows Phone 8? Please a look at Multi-resolution apps for Windows Phone 8 . Here is the ResolutionHelper class you can use.
public enum Resolutions { WVGA, WXGA, HD720p };
public static class ResolutionHelper
{
private static bool IsWvga
{
get
{
return App.Current.Host.Content.ScaleFactor == 100;
}
}
private static bool IsWxga
{
get
{
return App.Current.Host.Content.ScaleFactor == 160;
}
}
private static bool Is720p
{
get
{
return App.Current.Host.Content.ScaleFactor == 150;
}
}
public static Resolutions CurrentResolution
{
get
{
if (IsWvga) return Resolutions.WVGA;
else if (IsWxga) return Resolutions.WXGA;
else if (Is720p) return Resolutions.HD720p;
else throw new InvalidOperationException("Unknown resolution");
}
}
}
You Target your app for Windows Phone 7.1 , so you should update your app to target windows phone 8.0 OS by clicking right on your project and Upgrade to Windows Phone 8.0

Resources