Giter Site home page Giter Site logo

deviceinfoplugin's Introduction

Device Information Plugin for Xamarin and Windows

Simple way of getting common device information in Xamarin.iOS, Xamarin.Android, Windows, and Xamarin.Forms projects.

Setup

Build status: Build status

I have been working on Plugins for Xamarin for a long time now. Through the years I have always wanted to create a single, optimized, and official package from the Xamarin team at Microsoft that could easily be consumed by any application. The time is now with Xamarin.Essentials, which offers over 50 cross-platform native APIs in a single optimized package. I worked on this new library with an amazing team of developers and I highly highly highly recommend you check it out.

Additionally, Xamarin.Essentials is now included in & .NET MAUI.

Due to the functionality being included "in the box" I have decided to officially archive this repo.

Platform Support

Platform Version
Xamarin.iOS iOS 7+
Xamarin.Android API 13+
Windows 10 UWP 10+
Xamarin.Mac All
Xamarin.Mac All
watchOS All
tvOS All
Tizen 4.0+

API Usage

Call CrossDeviceInfo.Current from any project or PCL to gain access to APIs.

GenerateAppId Used to generate a unique Id for your app.

/// <summary>
/// Generates a an AppId optionally using the PhoneId a prefix and a suffix and a Guid to ensure uniqueness
///
/// The AppId format is as follows {prefix}guid{phoneid}{suffix}, where parts in {} are optional.
/// </summary>
/// <param name="usingPhoneId">Setting this to true adds the device specific id to the AppId (remember to give the app the correct permissions)</param>
/// <param name="prefix">Sets the prefix of the AppId</param>
/// <param name="suffix">Sets the suffix of the AppId</param>
/// <returns></returns>
string GenerateAppId(bool usingPhoneId = false, string prefix = null, string suffix = null);

Id This should not be used as a stable ID as each vendor on Android may or may not set it to a different value and on iOS it is changed when applications are uninstalled.

/// <summary>
/// This is the device specific Id (remember the correct permissions in your app to use this)
/// </summary>
string Id { get; }

Device Model

/// <summary>
/// Get the model of the device
/// </summary>
string Model { get; }

Manufacturer

/// <summary>
/// Get the name of the device
/// </summary>
string Manufacturer { get; }

DeviceName

/// <summary>
/// Get the name of the device
/// </summary>
string DeviceName { get; }

Version

/// <summary>
/// Gets the version of the operating system as a string
/// </summary>
string Version { get; }

Returns the specific version number of the OS such as:

  • iOS: 8.1
  • Android: 4.4.4
  • Windows Phone: 8.10.14219.0
  • UWP: 10.0.14393.105
  • Tizen: 4.0

VersionNumber

/// <summary>
/// Gets the version number of the operating system as a Version
/// </summary>
Version VersionNumber { get; }

AppVersion

/// <summary>
/// Returns the current version of the app, as defined in the PList, e.g. "4.3".
/// </summary>
/// <value>The current version.</value>
string AppVersion { get; }

AppBuild

/// <summary>
/// Returns the current build of the app, as defined in the PList, e.g. "4300".
/// </summary>
/// <value>The current build.</value>
string AppBuild { get; }

Platform

/// <summary>
/// Get the platform of the device
/// </summary>
Platform Platform { get; }

Returns the Platform enum of:

public enum Platform
{
    Android,
    iOS,
    WindowsPhone,
    Windows,
    WindowsTablet,
    SurfaceHub,
    Xbox,
    IoT,
    Unknown,
    tvOS,
    watchOS,
    macOS,
    Tizen
}

Idiom

/// <summary>
/// Get the idom of the device
/// </summary>
Idiom Idiom { get; }

Returns the Idiom enum of:

public enum Idiom
{
    Unknown,
    Car,
    Desktop,
    Phone,
    Tablet,
    TV,
    Watch
}

IsDevice

/// <summary>
/// Checks whether this is a real device or an emulator/simulator
/// </summary>
bool IsDevice { get; }

Returns true, if the app is running on a real physical device. false is returned if the app is running on an emulator or simulator (whatever applies for the platform).

Additional Android Setup

This plugin uses the Current Activity Plugin to get access to the current Android Activity. Be sure to complete the full setup if a MainApplication.cs file was not automatically added to your application. Please fully read through the Current Activity Plugin Documentation. At an absolute minimum you must set the following in your Activity's OnCreate method:

Plugin.CurrentActivity.CrossCurrentActivity.Current.Init(this, bundle);

It is highly recommended that you use a custom Application that are outlined in the Current Activity Plugin Documentation](https://github.com/jamesmontemagno/CurrentActivityPlugin/blob/master/README.md)

Contributions

Contributions are welcome! If you find a bug please report it and if you want a feature please report it.

If you want to contribute code please file an issue and create a branch off of the current dev branch and file a pull request.

License

Under MIT, see LICENSE file.

deviceinfoplugin's People

Contributors

aer127 avatar jamesmontemagno avatar jongheonchoi avatar kzu avatar lunelake avatar mkuckert avatar rookiejava avatar tayoufabrice avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

deviceinfoplugin's Issues

Getting IMEI of device

Can you add getting IMEI or list of IMEIs(in case of dual-sim devices) to your features?
Thanks.

Won't install in my .Net Standard 2.0 project

Bug Information

Version Number of Plugin: 3.1.0
Device Tested On: Samsung S5 Neo
Simulator Tested On:
Version of VS: 2017 15.5.7
Version of Xamarin: 4.8.0.760
Versions of other things you are using: Xamarin Forms app with .NET Standard 2.0

Steps to reproduce the Behavior

  • Create a new Xamarin Forms app and choose .Net Standard 2.0
  • Install the package in a .NET Standard 2.0 project (not PCL)

Expected Behavior

Package installed

Actual Behavior

It installs on the Android and iOS project, but not in the .Net Standard 2.0 project

Install-Package Xam.Plugin.DeviceInfo -Version 3.1.0
GET https://api.nuget.org/v3/registration3-gz-semver2/xam.plugin.deviceinfo/index.json
OK https://api.nuget.org/v3/registration3-gz-semver2/xam.plugin.deviceinfo/index.json 250ms
GET https://dotnet.myget.org/F/aspnetcore-dev/Packages(Id='Xam.Plugin.DeviceInfo',Version='3.1.0')
GET http://nuget.syncfusion.com/nuget_xamarin/nuget/getsyncfusionpackages/xamarin/Packages(Id='Xam.Plugin.DeviceInfo',Version='3.1.0')
Error finding repository for 'https://www.myget.org/F/aspnetvnext/': An error occurred while retrieving package metadata for 'Xam.Plugin.DeviceInfo.3.1.0' from source 'AspnetVnext'.
A task was canceled.
Error finding repository for 'http://nuget.syncfusion.com/nuget_xamarin/nuget/getsyncfusionpackages/xamarin': An error occurred while retrieving package metadata for 'Xam.Plugin.DeviceInfo.3.1.0' from source 'Syncfusion_Xamarin'.
A task was canceled.
Restoring packages for R:\VeloGuide\VeloGuideApp\VeloGuideApp\VeloGuideApp\VeloGuideApp.csproj...
Installing NuGet package Xam.Plugin.DeviceInfo 3.1.0.
Committing restore...
Writing lock file to disk. Path: R:\VeloGuide\VeloGuideApp\VeloGuideApp\VeloGuideApp\obj\project.assets.json
Restore completed in 258.04 ms for R:\VeloGuide\VeloGuideApp\VeloGuideApp\VeloGuideApp\VeloGuideApp.csproj.
Committing restore...
Assets file has not changed. Skipping assets file writing. Path: R:\VeloGuide\VeloGuideApp\VeloGuideApp\VeloGuideApp.iOS\obj\project.assets.json
Restore completed in 23.87 ms for R:\VeloGuide\VeloGuideApp\VeloGuideApp\VeloGuideApp.iOS\VeloGuideApp.iOS.csproj.
Committing restore...
Assets file has not changed. Skipping assets file writing. Path: R:\VeloGuide\VeloGuideApp\VeloGuideApp\VeloGuideApp.Android\obj\project.assets.json
Restore completed in 35.46 ms for R:\VeloGuide\VeloGuideApp\VeloGuideApp\VeloGuideApp.Android\VeloGuideApp.Android.csproj.

NuGet Config files used:
C:\Users\stesv\AppData\Roaming\NuGet\NuGet.Config
C:\Program Files (x86)\NuGet\Config\Microsoft.VisualStudio.Offline.config
C:\Program Files (x86)\NuGet\Config\Microsoft.VisualStudio.Offline.Fallback.config

Feeds used:
C:\Program Files (x86)\Microsoft SDKs\NuGetPackages
http://nuget.syncfusion.com/nuget_xamarin/nuget/getsyncfusionpackages/xamarin
https://api.nuget.org/v3/index.json
https://www.myget.org/F/aspnetvnext/
Executing nuget actions took 171.52 ms
Time Elapsed: 00:00:01.8669523

Code snippet

var appVersion = CrossDeviceInfo.Current.AppVersion;

Screenshotst

image

TypeLoadException when loading Android F# Libraries

If you are creating an issue for a BUG please fill out this information. If you are asking a question or requesting a feature you can delete the sections below.

Failure to fill out this information will result in this issue being closed. If you post a full stack trace in a bug it will be closed, please post it to http://gist.github.com and then post the link here.

Bug Information

Version Number of Plugin: 4.0.0.13
Device Tested On: Samsung G925F (Android 7.0 API 24)
Simulator Tested On:
Version of VS: 15.7.2
Version of Xamarin: 4.10.0.448
Versions of other things you are using:

Steps to reproduce the Behavior

Create an F# Android class library
Package it up as a NuGet package
Create an F# Android application and reference the generated NuGet package
Run the F# Android application.

Expected Behavior

The Android app should launch

Actual Behavior

On launch, the app crashes with the message
System.TypeLoadException: Could not resolve type with token 01000078 (from typeref, class/assembly Plugin.DeviceInfo.Abstractions.IDeviceInfo, Plugin.DeviceInfo, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null) occurred

Code snippet

Screenshotst

Implementation of MainApplication in the library:
image

Using with portable library throws exception - expected?

Hi there @jamesmontemagno, appreciate your work with this library, the API is very simple. :)

I am working on trying to implement this in Stripe.net. I noticed this code block:

#if PORTABLE
        return null;
#else
        return new DeviceInfoImplementation();
#endif

Seeing as my project has a .NET 4.5 version and a portable version that works for Xamarin, this will always return null on the portable version of the assembly. Is this expected, or am I doing something wrong? Also, is this intended to work for a regular .NET assembly as well?

Thanks much!

Mac OS retrieve different IDs for the same device

I have a Macbook Pro in which I tried to create a MacOS version of my app
Every devices used are indexed by their Id which is supposed to be unique. For my Mac I got many different IDs

Ex.
5B5DDEA3-7B09-4D6B-XXXX-D42F1D84814D
FA1E24F4-DCC5-4BA0-XXXX-D8B015C52EED
98FD8A6E-8F14-4F77-XXXX-C83EEA9DFCCC

(the xxxx are used to obfuscate the IDs in any case)

Bug Information

Version Number of Plugin: 3.1.0.57
Device Tested On: Mac
Simulator Tested On:Real machine
Version of VS: 2017 (15.5.3)
Version of Xamarin:
Versions of other things you are

PS.
Also the Idiom gives Phone (3) and model is iPhone

DeviceName returns an error

Bug Information:

Version of Plugin: 3.1.0.57-beta
Tested on: Android 6 API 23 - Samsung Galaxy 5
VS: 2017 15.5.4
Xamarin: 4.8.0.757
Xamarin Forms: 2.5.0.122203

Running CrossDeviceInfo.Current.DeviceName causes an Exception Error:

01-24 09:16:15.077 I/MonoDroid( 9139): UNHANDLED EXCEPTION:
01-24 09:16:15.137 I/MonoDroid( 9139): System.MissingMethodException: Method 'Plugin.DeviceInfo.Abstractions.IDeviceInfo.get_DeviceName' not found.
01-24 09:16:15.137 I/MonoDroid( 9139): at System.Runtime.CompilerServices.AsyncVoidMethodBuilder.Start[TStateMachine] (TStateMachine& stateMachine) [0x0002c] in <657aa8fea4454dc898a9e5f379c58734>:0

CrossDeviceInfo.Current.Version and Platform and Model work fine.

[Additional feature request] DeviceInfo Plugin to make available Device Hardware (ie iPhone10,3 for iPhoneX)

Hi James
I use a number of your Plugins, which are all great and easy to use.
I need to be able to detect iPhoneX in my app and I donโ€™t want to use the device screen size to determine the hardware type due to the potential issues for future maintenance.
I have found a post by Bag Labs that includes a solution using XLabs, which I donโ€™t use.
Just a thought that a useful extension to your DeviceInfo Plugin would be to return the Hardware name.
Thanks
John

Compatibility with macOS via Visual Studio 7.0

Bug

Im receiving errors installing your plugin on macOS. Perhaps it could be caused by recent changes to the Xamarin mac runtime.

Version Number of Plugin: 2.1.2
Device Tested On: mac x86 running Sierra 10.12.4 OS

Expected Behaviour

Plugin installs

Actual Behaviour

Receive error.

Could not install package 'Xam.Plugin.DeviceInfo 2.1.2'. You are trying to install this package into a project that targets 'Xamarin.Mac,Version=v2.0', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.

Steps to reproduce the Behaviour

Install Visual Studio 7.0
Attempt to add DeviceInfo to macOS target

DeviceName returns missingMethodException

If you are creating an issue for a BUG please fill out this information. If you are asking a question or requesting a feature you can delete the sections below.

Failure to fill out this information will result in this issue being closed. If you post a full stack trace in a bug it will be closed, please post it to http://gist.github.com and then post the link here.

Bug Information

Version Number of Plugin: 3.1.0.0
Device Tested On: Samsung Galaxy
Simulator Tested On: 10 devices on google play logcat
Version of VS: VS 2017
Version of Xamarin: 2.5
Versions of other things you are using:

Steps to reproduce the Behavior

this is all I have to do and it crashes on device

var di = GetDeviceInfo;
var deviceName = di.DeviceName;

this error is thrown
System.MissingMethodException: string Plugin.DeviceInfo.Abstractions.IDeviceInfo.get_DeviceName()

Expected Behavior

get the device Name

Actual Behavior

System.MissingMethodException: string Plugin.DeviceInfo.Abstractions.IDeviceInfo.get_DeviceName()

Code snippet

var di = GetDeviceInfo;
var deviceName = di.DeviceName;

Screenshotst

System.NotImplementedException -This functionality is not implemented in the portable version of this assembly

Hi James

A strange problem..

A have 2 almost identical apps, where i use the plugin.

Suddenly only the one APP, throws an exception in Android (device and simulator)

System.NotImplementedException
This functionality is not implemented in the portable version of this assembly. You should reference the NuGet package from your main application project in order to reference the platform-specific implementation.

I have tried uninstalling/re-installing the plugin, ad also tried re-install all nuget packes, but nothings helps. OIS is working fine.
The plugin is installed in PCL and target projekts

This is my packages.config:

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="Microsoft.Bcl" version="1.1.10" targetFramework="monoandroid60" />
  <package id="Microsoft.Bcl.Build" version="1.0.21" targetFramework="monoandroid60" />
  <package id="Microsoft.Bcl.Compression" version="3.9.85" targetFramework="monoandroid60" />
  <package id="Microsoft.Net.Http" version="2.2.29" targetFramework="monoandroid60" />
  <package id="modernhttpclient" version="2.4.2" targetFramework="monoandroid60" />
  <package id="Newtonsoft.Json" version="9.0.1" targetFramework="MonoAndroid60" />
  <package id="Plugin.CurrentActivity" version="1.0.1" targetFramework="monoandroid60" />
  <package id="Plugin.Permissions" version="1.2.1" targetFramework="monoandroid60" />
  <package id="Plugin.VersionTracking" version="1.0.1" targetFramework="monoandroid60" />
  <package id="SQLite.Net.Core-PCL" version="3.1.1" targetFramework="monoandroid60" />
  <package id="SQLite.Net-PCL" version="3.1.1" targetFramework="monoandroid60" />
  <package id="Xam.Plugin.DeviceInfo" version="2.1.2" targetFramework="monoandroid70" />
  <package id="Xam.Plugin.Geolocator" version="3.0.4" targetFramework="MonoAndroid60" />
  <package id="Xam.Plugin.Media" version="2.6.2" targetFramework="monoandroid70" />
  <package id="Xam.Plugins.Settings" version="2.5.4" targetFramework="monoandroid71" />
  <package id="Xamarin.Android.Support.Animated.Vector.Drawable" version="23.3.0" targetFramework="MonoAndroid60" />
  <package id="Xamarin.Android.Support.Design" version="23.3.0" targetFramework="MonoAndroid60" />
  <package id="Xamarin.Android.Support.v4" version="23.3.0" targetFramework="MonoAndroid60" />
  <package id="Xamarin.Android.Support.v7.AppCompat" version="23.3.0" targetFramework="MonoAndroid60" />
  <package id="Xamarin.Android.Support.v7.CardView" version="23.3.0" targetFramework="MonoAndroid60" />
  <package id="Xamarin.Android.Support.v7.MediaRouter" version="23.3.0" targetFramework="MonoAndroid60" />
  <package id="Xamarin.Android.Support.v7.RecyclerView" version="23.3.0" targetFramework="MonoAndroid60" />
  <package id="Xamarin.Android.Support.Vector.Drawable" version="23.3.0" targetFramework="MonoAndroid60" />
  <package id="Xamarin.Azure.NotificationHubs.Android" version="0.4.0" targetFramework="monoandroid70" />
  <package id="Xamarin.Forms" version="2.3.3.193" targetFramework="monoandroid71" />
  <package id="Xamarin.GooglePlayServices.Base" version="29.0.0.1" targetFramework="monoandroid71" />
  <package id="Xamarin.GooglePlayServices.Basement" version="29.0.0.1" targetFramework="monoandroid71" />
  <package id="Xamarin.GooglePlayServices.Gcm" version="29.0.0.1" targetFramework="monoandroid71" />
  <package id="Xamarin.GooglePlayServices.Measurement" version="29.0.0.1" targetFramework="monoandroid71" />
  <package id="Xamarin.Insights" version="1.12.3" targetFramework="MonoAndroid60" />
  <package id="ZXing.Net.Mobile" version="2.1.47" targetFramework="monoandroid60" />
  <package id="ZXing.Net.Mobile.Forms" version="2.1.47" targetFramework="monoandroid60" />
</packages>

[Feature Request] Add watchOS support

Please fill out either the bug or feature request section and remove whatever section you are not using.

Bug

Version Number of Plugin:
Device Tested On:
Simulator Tested On:

Expected Behavior

Actual Behavior

Steps to reproduce the Behavior

Feature Request:

Please fill in what you would like

Id is not working stable

I used this lib for Production. And after few days running, I found out that Id is not working properly.
A lot of devices return Id as "0123456789ABCDEF", or "0123456789012345678901234567890" or empty, sure, that's not correct. Please check attached file for details.
Appreciate to hear any update from you :)
id_wrong

There is no DeviceInfo.Plugin as in your example

Using a PCL in Xamarin.Forms, DeviceInfo Nuget was added to all three platforms.

In my Pcl class I add "using DeviceInfo.Plugin " and it doesn't exist, however,
it corrects me into adding "Plugins.DeviceInfo" but there is not a .Plugins Property after that, only a .Abstractions?

What am I doing wrong?

CrossDeviceInfo.Current.Id throws no static method "Landroid/os/Build;.getSerial()Ljava/lang/String;"

This bug happens after I've upgraded to the beta channel.

Bug Information

Version Number of Plugin: 3.0.1
Device Tested On: LGE Nexus 4 (API 22), HUAWEIVNS-L31 (API 24)
Version of VS: 7.2 preview (build 634)
Version of Xamarin:

Xamarin.Forms: 2.4.0.282
Xamarin.Android: 8.0.0.33

Steps to reproduce the Behavior

Simply call CrossDeviceInfo.Current.Id

Stacktrace

Java.Lang.NoSuchMethodError: no static method "Landroid/os/Build;.getSerial()Ljava/lang/String;"
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <896ad1d315ca4ba7b117efb8dacaedcf>:0 
  at Java.Interop.JniEnvironment+StaticMethods.GetStaticMethodID (Java.Interop.JniObjectReference type, System.String name, System.String signature) [0x0005b] in <1d799d87381c4db5b1252825fd105b84>:0 
  at Java.Interop.JniType.GetStaticMethod (System.String name, System.String signature) [0x0000c] in <1d799d87381c4db5b1252825fd105b84>:0 
  at Java.Interop.JniPeerMembers+JniStaticMethods.GetMethodInfo (System.String encodedMember) [0x00036] in <1d799d87381c4db5b1252825fd105b84>:0 
  at Java.Interop.JniPeerMembers+JniStaticMethods.InvokeObjectMethod (System.String encodedMember, Java.Interop.JniArgumentValue* parameters) [0x00000] in <1d799d87381c4db5b1252825fd105b84>:0 
  at Android.OS.Build.get_Serial () [0x0000a] in <c82a099136944d8aa96281cf061cbc12>:0 
  at Plugin.DeviceInfo.DeviceInfoImplementation.get_Id () [0x00014] in C:\projects\deviceinfoplugin\src\DeviceInfo.Plugin.Android\DeviceInfoImplementation.cs:61 

Device Name

Feature Request:

Is it possible to get the Device Name using this plugin, if not could this be added easily, this would really be helpful

Device screen size

Is it possible to get screen size (height and width) in pixels through this plugin?

Can't find DeviceName and other properties

I just installed this plugin to get the device name but the property doesn't appear. I thought it's supposed to appear when I enter CrossDeviceInfo.Current.DeviceName but the only properties I see are

  • Id
  • Idiom
  • Model
  • Platform
  • Version
  • VersionNumber

Where can I find the DeviceName property?

I am using version 3.0.2

I've just looked into the source code here on Github and the interface has the property DeviceName.

DeviceInfoPlugin Opens Camera and Read/Write Permissions

Good day Sir @jamesmontemagno,

I was using your plugin for Xamarin Forms project due to the need of getting the device info. Your plugin works perfectly for what I need. However, it enabled my android CAMERA and READ/WRITE permissions and I don't have any idea how to disable it. The client really wants to disable these permissions when installing the APK.

I already tried to explicitly add tools:remove to the camera permission in the AndroidManifest.xml file but it still keeps the permissions.

<uses-permission android:name="android.permission.CAMERA tools:node="remove">

Is there any way to disable these permissions using this plugin or any alternative solutions to do so.

Any suggestions would be very much appreciated. I wouldn't want to end up removing your plugin just because of this problem.

Best regards,
Jan

screenshot_2018-03-27-11-34-32-367_com google android packageinstaller

How to use with net standard unit tests?

Got version 3.1.0 of the NuGet package and tried to use it with my net standard unit tests that are running on my MacBook. Whatever you call, you will get the following Exception:

NotImplementedException: This functionality is not implemented in the portable version of this assembly. You should reference the NuGet package from your main application project in order to reference the platform-specific implementation.

Is there a way to use this package with my net standard unit tests?

Definition of DeviceID

I'm not sure whether it's a bug or a feature request because I don't know the definition of the DeviceID. Summary says "This is the device specific Id".

It seems that this device ID is recalculated (at least on iOS) whenever I uninstall and install the same app again (also reported in #13 where the link in the last comment does not work anymore ) and it also recalculates if the OS is updated (seen by updating from iOS 10.2.1 to iOS 10.3.1). Is this correct? And if so, is it a bug or the expected behaviour?

I thought the ID would give a unique ID for a unique device, regardless of updates of my App, re-installation of my app, update of OS etc. Obviously that's not the case, at least for iOS.

Is there a way with current plugin to get such unique ID? If not, is there any other way for Xamarin Forms?
Many thanks!

[Bug] Invalid Cast WP8.1RT when querying Id

Copied from: jamesmontemagno/Xamarin.Plugins#273

Bug

Version Number of Plugin: 2.0.2
Device Tested On:
Simulator Tested On: Emulator 8.1 WVGA 512 Mb

Expected Behavior

get the generated GUID

Actual Behavior

Sometimes the system returned to me :

Unable to cast object of type 'System.__ComObject' to type 'Windows.System.Profile.IHardwareIdentificationStatics'

With this StackTrace :
at System.StubHelpers.StubHelpers.GetCOMIPFromRCW_WinRT(Object objSrc, IntPtr pCPCMD, IntPtr& ppTarget)
at Windows.System.Profile.HardwareIdentification.GetPackageSpecificToken(IBuffer nonce)
at Plugin.DeviceInfo.DeviceInfoImplementation.get_Id()

Steps to reproduce the Behavior

I ask for the CrossDeviceInfo.Current.Id at multiple times in the OnLaunched method of App.xaml.cs

(i resolved by stocked the id the first time now but i get this back to you if it can help you to improve this awesome plugin ^^)

Id

Expected Behavior

Hi,

is that the IMIE of a device?

thanks,
Eric

Model iPhone Number

Please fill out either the bug or feature request section and remove whatever section you are not using.

Bug

Version Number of Plugin: 2.1.0.2-beta
Device Tested On: iPhone6
Simulator Tested On: -

Expected Behavior

Would expect if I call CrossDeviceInfo.Current.Model I would get

iPhone6

Actual Behavior

If I call CrossDeviceInfo.Current.Model I get just

iPhone

Thanks a lot for your great work!

AppVersionNumber Include Build Number?

Could/Should AppVersionNumber include the Build number? I use this to explicitly see build versions when building through Mobile Center. Currently I have a simple DependencyService which does the following. Would love to be able to eliminate and just use AppVersionNumber.

iOS CFBundleVersion:

NSBundle.MainBundle.ObjectForInfoDictionary("CFBundleShortVersionString").ToString() + "." + NSBundle.MainBundle.ObjectForInfoDictionary("CFBundleVersion");

Android VersionCode:

 var context = Android.App.Application.Context;
 var pInfo = context.PackageManager.GetPackageInfo(context.PackageName, 0);
 return pInfo.VersionName + "." + pInfo.VersionCode;

UWP Build:

PackageVersion version = Package.Current.Id.Version;
return $"{version.Major}.{version.Minor}.{version.Build}";

Idiom return NullReferenceException

Version Number of Plugin: 3.0.2
Device Tested On: Sansung Galaxy S7 Edge
Simulator Tested On: VS Emulator 5.7-inch Marshmallow (6.0.0) XHDPI Phone
Version of VS: 15.4.2
Version of Xamarin: 2.5.0.77107
Versions of other things you are using: Prism.Ninject 7.0.0.168 pre

Steps to reproduce the Behavior

In the App. xaml. cs class or any other:
var deviceInfo = CrossDeviceInfo. Current;
ToString ();

Expected Behavior

Get device language

Actual Behavior

NullReferenceExpection

Code snippet

var deviceInfo = CrossDeviceInfo.Current; device.Idiom = device.Idiom.ToString(); device.VersionNumber = deviceInfo.VersionNumber.ToString(); device.Model = deviceInfo.Model; device.Plataform = deviceInfo.Platform.ToString(); device.Version = deviceInfo.Version.ToString(); device.SerialNumber = deviceInfo.Id.ToString();

Screenshotst

sin titulo

'CrossDeviceInfo' does not exist in the current context

I have installed the plugin through NuGet (version 2.0.2) into the Core and clients projects, but I cannot use it...it says that the class 'CrossDeviceInfo' does not exist in the current context.

What can be happening?

EDITED: just resolved uninstalling - installing again

Gotten "unknown" Device ID

Bug

In some circumstances, it returns "unknown" for device id. It is a real Android device. Plugin still be able to get the Model (M708S) and Version (4.2.2)

Version Number of Plugin: 1.0.0.2
Device Tested On: M708S (Model)
Simulator Tested On:

Expected Behavior

Return with a unique device ID

Actual Behavior

Return "unknown"

Android Device ID=0 because Serial Number is 0

Bug Information

Version Number of Plugin: 3.0.1
Device Tested On: Android 5.1 Model N501
Version of VS: 2015 Update 3
Version of Xamarin: 4.7.9.45
Versions of other things you are using: Xamarin.Adroid 7.4.5.1

Steps to reproduce the Behavior

When the Serial Number of the Android phone is zero CrossDeviceInfo.Current.Id returns 0

Expected Behavior

Checking the code I see that if the Serial Number is Unknown then try to get the android id. I think the best behaviour would be that in case of Serial Number 0 try to get the android id too.

Screenshotst

Case with Serial Number cero.

skp_20171020_122217_1371221794328

iOS Every Uninstall/Install gives new Id

Please fill out either the bug or feature request section and remove whatever section you are not using.

Bug

Version Number of Plugin: 2.0.2
Device Tested On: iPhone 6s
Simulator Tested On: NA

Expected Behavior

Globally unique but same at device level, id every time the app runs [Irrespective of uninstall and install several times]

Actual Behavior

Every time the SAME app is uninstalled and installed, returned id is different. So can not use it like UDID.

Steps to reproduce the Behavior

Feature Request:

Please fill in what you would like
It seems its the implementation but I would really like to use id as UDID. Any other way to get that on iOS?
BTW for android its unique per device but same for different apps so it can be used as UDID.

Building the code

I'm trying to build master but can't.
I have tried on:

Visual Studio for Mac (7.4.3 build 10)
Visual Studio on Windows (15.7 with Xamarin/UWP workloads)
.NET Core CLI (2.1.101)
MSBuild on macOS (15.4.0.0 (xplat-master/67e8006d Thu Mar 8 17:15:24 EST 2018) for Mono)

VS for mac fails with:

/Users/bruno/git/DeviceInfoPlugin/src/DeviceInfo.Plugin/DeviceInfo.Plugin.csproj: Error NU1202: Package Plugin.CurrentActivity 2.0.0.6-beta is not compatible with netstandard1.0 (.NETStandard,Version=v1.0). Package Plugin.CurrentActivity 2.0.0.6-beta supports: monoandroid44 (MonoAndroid,Version=v4.4) (NU1202) (DeviceInfo.Plugin) ...

On Windows it's a MSBuild issue:

Severity Code Description Project File Line Suppression State
Error MSB4057 The target "Clean" does not exist in the project. DeviceInfo.Plugin C:\Users\bruno\git\DeviceInfoPlugin\src\DeviceInfo.Plugin\DeviceInfo.Plugin.csproj 1

CLI:

/usr/local/share/dotnet/sdk/2.1.101/Sdks/Microsoft.NET.Sdk/Sdk/Sdk.targets(41,3): error MSB4019: The imported project "/usr/local/share/dotnet/sdk/2.1.101/15.0/Bin/Microsoft.CSharp.targets" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk. [/Users/bruno/git/DeviceInfoPlugin/src/DeviceInfo.Plugin/DeviceInfo.Plugin.csproj] /Users/bruno/git/DeviceInfoPlugin/src/DeviceInfo.Plugin/DeviceInfo.Plugin.csproj : error MSB4057: The target "Build" does not exist in the project. /Users/bruno/git/DeviceInfoPlugin/src/DeviceInfo.Plugin/DeviceInfo.Plugin.csproj : error MSB4057: The target "Build" does not exist in the project. /Users/bruno/git/DeviceInfoPlugin/src/DeviceInfo.Plugin/DeviceInfo.Plugin.csproj : error MSB4057: The target "Build" does not exist in the project. /Users/bruno/git/DeviceInfoPlugin/src/DeviceInfo.Plugin/DeviceInfo.Plugin.csproj : error MSB4057: The target "Build" does not exist in the project. /Users/bruno/git/DeviceInfoPlugin/src/DeviceInfo.Plugin/DeviceInfo.Plugin.csproj : error MSB4057: The target "Build" does not exist in the project. /Users/bruno/git/DeviceInfoPlugin/src/DeviceInfo.Plugin/DeviceInfo.Plugin.csproj : error MSB4057: The target "Build" does not exist in the project. 0 Warning(s) 7 Error(s)

MSBuild failed like VS for Mac as expected:

/Users/bruno/git/DeviceInfoPlugin/src/DeviceInfo.Plugin/DeviceInfo.Plugin.csproj : error NU1202: Package System.Threading.Timer 4.0.1 is not compatible with netstandard1.0 (.NETStandard,Version=v1.0). Package System.Threading.Timer 4.0.1 supports: /Users/bruno/git/DeviceInfoPlugin/src/DeviceInfo.Plugin/DeviceInfo.Plugin.csproj : error NU1202: - monoandroid10 (MonoAndroid,Version=v1.0) /Users/bruno/git/DeviceInfoPlugin/src/DeviceInfo.Plugin/DeviceInfo.Plugin.csproj : error NU1202: - monotouch10 (MonoTouch,Version=v1.0) /Users/bruno/git/DeviceInfoPlugin/src/DeviceInfo.Plugin/DeviceInfo.Plugin.csproj : error NU1202: - net451 (.NETFramework,Version=v4.5.1) /Users/bruno/git/DeviceInfoPlugin/src/DeviceInfo.Plugin/DeviceInfo.Plugin.csproj : error NU1202: - netcore50 (.NETCore,Version=v5.0) /Users/bruno/git/DeviceInfoPlugin/src/DeviceInfo.Plugin/DeviceInfo.Plugin.csproj : error NU1202: - netstandard1.2 (.NETStandard,Version=v1.2) /Users/bruno/git/DeviceInfoPlugin/src/DeviceInfo.Plugin/DeviceInfo.Plugin.csproj : error NU1202: - portable-net451+win81+wpa81 (.NETPortable,Version=v0.0,Profile=Profile151) /Users/bruno/git/DeviceInfoPlugin/src/DeviceInfo.Plugin/DeviceInfo.Plugin.csproj : error NU1202: - win81 (Windows,Version=v8.1) /Users/bruno/git/DeviceInfoPlugin/src/DeviceInfo.Plugin/DeviceInfo.Plugin.csproj : error NU1202: - wpa81 (WindowsPhoneApp,Version=v8.1) /Users/bruno/git/DeviceInfoPlugin/src/DeviceInfo.Plugin/DeviceInfo.Plugin.csproj : error NU1202: - xamarinios10 (Xamarin.iOS,Version=v1.0) /Users/bruno/git/DeviceInfoPlugin/src/DeviceInfo.Plugin/DeviceInfo.Plugin.csproj : error NU1202: - xamarinmac20 (Xamarin.Mac,Version=v2.0) /Users/bruno/git/DeviceInfoPlugin/src/DeviceInfo.Plugin/DeviceInfo.Plugin.csproj : error NU1202: - xamarintvos10 (Xamarin.TVOS,Version=v1.0) /Users/bruno/git/DeviceInfoPlugin/src/DeviceInfo.Plugin/DeviceInfo.Plugin.csproj : error NU1202: - xamarinwatchos10 (Xamarin.WatchOS,Version=v1.0)

Do I need to install anything else to get it to build?

Unit Test for Shared Project

I am want to Unit Test some of my code that consumes DeviceInfo.

I found that if I use a Shared Project Unit Test on some methods that call into Device Info, that it throws an exeption of not having the Mono.Android runtime for some of the items, but not all of them. This is because it is being called from Unit Test Project, via the Android Project

Version 2.1.2

Returns values
CrossDeviceInfo.Current.Platform.ToString();
CrossDeviceInfo.Current.GenerateAppId().ToString();
CrossDeviceInfo.Current.VersionNumber.ToString();

Exception (Mono.Android runtime missing)
CrossDeviceInfo.Current.Model.ToString();
CrossDeviceInfo.Current.Idiom.ToString();
CrossDeviceInfo.Current.Version.ToString();
CrossDeviceInfo.Current.Id;

How are you able to Unit Test in a Shared Project using VS Unit Test Projects?

Attempting to JIT compile method ... while running in aot-only mode.

Bug Information

Version Number of Plugin: 4.0.0.5
Device Tested On: iPhone 6Plus
Simulator Tested On: Version 10.0
Version of VS: Visual Studio for Mac 7.5 (build 1254)
Version of Xamarin: Xamarin.Forms package version 2.5.0.122203
Xamarin.iOS
Version: 11.10.1.177 (Visual Studio Professional)

Steps to reproduce the Behavior

Added call to CrossDeviceInfo.Current.Platform in code.

Expected Behavior

No crash

Actual Behavior

Method containing this call cannot be executed on device (Works fine within simulator).
Fails with:

System.ExecutionEngineException has been thrown
Attempting to JIT compile method 'Acc.C.ThemeManager:SetCurrentTheme (string)' while running in aot-only mode. See https://developer.xamarin.com/guides/ios/advanced_topics/limitations/ for more information.

Code snippet

public void SetCurrentTheme(String aTheme)
{
...
if(CrossDeviceInfo.Current.Platform == Platform.iOS)
Application.Current.Resources.Add("AISeparatorVisibility", SeparatorVisibility.None);
else
Application.Current.Resources.Add("AISeparatorVisibility", SeparatorVisibility.Default);
}

After removing this block of code, everything else works as expected.

Stacktrace at:
https://gist.github.com/kiwicodemonkey/9038bd117b313fb508ec0a2a2c67cde1

This error happens with any call to any CrossDeviceInfo method.

[Feature Request] Device or Simulator/Emulator

A property to distinguish a physical device from an simulator or emulator would be nice. This would add a simple way to enable some debugging features in dev environments.

Additions to the IDeviceInfo interface:

bool IsDevice { get; }

Additions to the iOS implementation:

public bool IsDevice => Runtime.Arch == Arch.DEVICE;

Additions to the Android implementation (detection is not as simple as on iOS - shamelessly taken from https://stackoverflow.com/a/13635166):

public bool IsDevice => !(
	Build.Fingerprint.StartsWith("generic", StringComparison.InvariantCulture)
	|| Build.Fingerprint.StartsWith("unknown", StringComparison.InvariantCulture)
	|| Build.Model.Contains("google_sdk")
	|| Build.Model.Contains("Emulator")
	|| Build.Model.Contains("Android SDK built for x86")
	|| Build.Manufacturer.Contains("Genymotion")
	|| (Build.Brand.StartsWith("generic", StringComparison.InvariantCulture) && Build.Device.StartsWith("generic", StringComparison.InvariantCulture))
	|| Build.Product.Equals("google_sdk", StringComparison.InvariantCulture)
);

I have no knowledge about the other platforms.

What do you think?

NotImplementedException

Hello. Thank you for your plugins!
I had added Xam.Plugin.DeviceInfo to PCL, Android and iOS projects (I don't use UWP in solution).
When I try to get CrossDeviceInfo.Current.Id I have this exception in my Xamarin PCL Project:
This functionality is not implemented in the portable version of this assembly. You should reference the NuGet package from your main application project in order to reference the platform-specific implementation.

Bug Information

Version Number of Plugin: 3.0.2
Device Tested On: Samsung Galaxy A5 2017
Simulator Tested On: -
Version of VS: 2017
Version of Xamarin: 2.5.0.121934
Versions of other things you are using:

WPF Support/.NET 4.5 Support

If you are creating an issue for a BUG please fill out this information. If you are asking a question or requesting a feature you can delete the sections below.

Failure to fill out this information will result in this issue being closed. If you post a full stack trace in a bug it will be closed, please post it to http://gist.github.com and then post the link here.

Bug Information

Version Number of Plugin:2.1.2
Device Tested On: Windows PC
Simulator Tested On:
Version of VS: 2015 update 3
Version of Xamarin:4.4.0.34
Versions of other things you are using: Dot net framework 4.2.6

Steps to reproduce the Behavior

I am trying to Use it for WPF Application and it crashes
issue

DeviceId issue

I am getting deviceId on windows (8.1 or 10) and android (min android version 4.4.2) devices and registering to database this Id for device validation. my app is installed on about 2000 real devices. I have some weird issues.
First issue is: same device could send me different deviceID
Second issue is: 2 or more device could send me same deviceId. Is this an issue or what is wrong ?

My plugin version 2.1.2. VS version is 2015 enterprise
Xamarin forms version: 2.3.3.180
Geolocator version: 4.0.0
Connectivity version: 2.3.0
Plugin.Permission version: 1.1.7
Prism version: 6.3.0-pre1

Why use Serial Number in Android?

Hi all,
a question regarding #24: As seen in #21, there are several Android devices which return dummy serial numbers, like "0123456789ABCDEF". As @jamesmontemagno describes there, he first checks for the serial, and if not returned, the Android_Id is checked. According to the linked Android Developer docs, Android_Id seems to be much more reliable (as it's created by Android itself) than the serial number (which is no surprise because the serial number is not reliable at all as there are many devices with dummy numbers).

In https://github.com/jamesmontemagno/DeviceInfoPlugin/blob/master/src/DeviceInfo.Plugin.Android/DeviceInfoImplementation.cs, I've removed lines 106-108 and 118 so I always use the Android_Id. This works fine on the emulator, and on my Wiko Lenny 3 with serial number "0123456789abcdef" ... I now get a (hopefully) unique string back (like "4e6e....").

So why is the serial number in Android used first? Maybe because the problems of the dummy serial numbers did not exist years ago, or are there any other reasons (security or else) why the Android_Id is not used in first place?

Many thanks!

P.S. So Android does have an ID (Android_Id) which is kept until user does a factory reset. Something similar for Apple still does not exist, so DeviceID is a new one on each uninstall and new installation of the app, right?

README Api Usage section out of date

At first glance of the README I went straight to API usage and saw the Platform enums shown as

public enum Platform
{
  Android,
  iOS,
  WindowsPhone,
  Windows
}

That isn't correct anymore. Also the Version string for WinRT works now, right? The README says it always returns "8.1", but looking at the code it seems to be properly parsing the version.

So this bug is to track updating the "Api Usage" section of README

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.