/// <summary>

        /// Retrieve the IMEI from the TelephonyManager

        /// </summary>

        /// <param name="context"></param>

        /// <returns></returns>

        public static string GetDeviceId(Context context)

        {

            TelephonyManager telephonyMgr =
context.GetSystemService(Context.TelephonyService) as TelephonyManager;

            string deviceId = telephonyMgr.DeviceId == null ? "UNAVAILABLE"
: telephonyMgr.DeviceId;

 

            return deviceId;

        }

 

        /// <summary>

        /// Retrieve the PhoneNumber from the TelephonyManager

        /// </summary>

        /// <param name="context"></param>

        /// <returns></returns>

        public static string GetPhoneNumber(Context context)

        {

            TelephonyManager telephonyMgr =
context.GetSystemService(Context.TelephonyService) as TelephonyManager;

            string phoneNumber = telephonyMgr.Line1Number == null ?
"UNAVAILABLE" : telephonyMgr.Line1Number;

 

            return phoneNumber;

        }

 

 

 

Von: monodroid-boun...@lists.ximian.com
[mailto:monodroid-boun...@lists.ximian.com] Im Auftrag von John Murray
Gesendet: Mittwoch, 20. Juli 2011 16:48
An: 'Discussions related to Mono for Android'
Betreff: [mono-android] getting IMEI

 

I need to obtain IMEI and phone number - I know I need read permissions but 

1)      There doesn't seem to be an implementation of
<http://developer.android.com/reference/android/telephony/TelephonyManager.h
tml#getDeviceId%28%29> android.telephony.TelephonyManager.getDeviceId().  In
mono I can only find GetObject

2)      Another java suggestion is to call 

a.  TelephonyManager telephonyManager =
(TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
telephonyManager.getDeviceId();

b.      But again Mono doesn't seem to do GetSystemService

 

Mono documentation suggests that one doesn't call Android.telephoney
directly but one should use
<http://docs.mono-android.net/Android.Content.Context.GetSystemService(Syste
m.String)> Android.Content.Context.GetSystemService(string)

This of course doesn't work in Mono and the documentation simply refers one
back to Android so I've reached an impasse

Can't see  any previous posts on this so - anyone got any ideas?

 

TIA

John Murray

_______________________________________________
Monodroid mailing list
Monodroid@lists.ximian.com

UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid

Reply via email to