2017-10-18 88 views
0

我期待在Xamarin Forms中使用C#獲取設備電話號碼。Xamarin Forms TelephonyManager,該程序集引用

我在另一篇文章中發現了這段代碼,但我不確定應該引用哪個程序集來使用它,誰能告訴我?

感謝

TelephonyManager tMgr = (TelephonyManager)mAppContext.getSystemService(Context.TELEPHONY_SERVICE); 
      String mPhoneNumber = tMgr.getLine1Number(); 

回答

1

這是Android Telephony Manager類,它可以在Android.Telephony命名空間中找到。

請記住,這是平臺特定的,只能在Android項目中使用。如果您嘗試創建跨平臺解決方案,那麼我建議您在包含GetPhoneInfo之類的方法的核心項目中創建一個接口,然後在兩個特定於平臺的類中實現此接口,該類使用正確的特定平臺代碼來檢索您之後的詳細信息。見this answer for more information on writing platform specific code in Xamarin Forms