我想獲取當前在手機中的SIM卡號碼,即所有者號碼。 和網絡模式,無論是GSM還是CDMA。如何獲取所有者/ SIM卡號碼和網絡模式
我在網上搜索並嘗試通過getLine1Number(); 但什麼也沒給
請幫我該怎麼做。
我想獲取當前在手機中的SIM卡號碼,即所有者號碼。 和網絡模式,無論是GSM還是CDMA。如何獲取所有者/ SIM卡號碼和網絡模式
我在網上搜索並嘗試通過getLine1Number(); 但什麼也沒給
請幫我該怎麼做。
對於你能做的電話號碼,
// Get the phone number from the telephony manager, and display it
TelephonyManager info = (TelephonyManager)getApplicationContext().getSystemService(Context.TELEPHONY_SERVICE);
String phoneNumber = info.getLine1Number();
對於網絡模式,請參閱TelephonyManager
這個問題已經被問了很多次的SO。
見How to get the mobile number of current sim card in real device?
而且,我必須補充一點,讓手機數量取決於運營商是否提供它的SIM卡或不上。
獲得烏爾SIM卡的數量,以及網絡U可以做到這一點:
TelephonyManager tm = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);
ConnectivityManager cm = (ConnectivityManager) this.getSystemService(Context.CONNECTIVITY_SERVICE);
if(cm.getActiveNetworkInfo().getTypeName().equals("MOBILE"))
network = "cellnetwork/3G";
else if(cm.getActiveNetworkInfo().getTypeName().equals("WIFI"))
network = "wifi";
else
network ="na";
uphone = tm.getLine1Number();
希望hepls :)
我已經試過了,和它的作品對我來說
要獲得電話號碼,請嘗試TelephonyManager。
如果這不起作用,您可以通過AccountManager獲取此信息。其中一個帳戶將是數字。
查看源細節實現對這個職位: TelephonyManager.getLine1Number() failing?