I have to make an application which shows the contact no of the SIM card that is being used in the cell. For that I need to use TelephonyManager
class. Can I get details on its usage?
我必须制作一个应用程序,显示单元格中使用的SIM卡的联系号码。为此,我需要使用TelephonyManager类。我可以获得它的用法细节吗?
6 个解决方案
#1
64
You can use the TelephonyManager
to do this:
您可以使用TelephonyManager执行此操作:
TelephonyManager tm = (TelephonyManager)getSystemService(TELEPHONY_SERVICE);
String number = tm.getLine1Number();
The documentation for getLine1Number()
says this method will return null
if the number is "unavailable", but it does not say when the number might be unavailable.
getLine1Number()的文档说如果数字“不可用”,这个方法将返回null,但是它没有说明数字何时可能不可用。
You'll need to give your application permission to make this query by adding the following to your Manifest:
您需要通过向Manifest添加以下内容来授予您的应用程序进行此查询的权限:
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
(You shouldn't use TelephonyManager.getDefault()
to get the TelephonyManager
as that is a private undocumented API call and may change in future.)
(您不应该使用TelephonyManager.getDefault()来获取TelephonyManager,因为这是一个私有的未记录的API调用,并且将来可能会更改。)
#2
6
Hi Actually this is my same question but I didn't get anything.Now I got mobile number and his email-Id from particular Android real device(Android Mobile).Now a days 90% people using what's App application on Android Mobile.And now I am getting Mobile no and email-ID Through this What's app API.Its very simple to use see this below code.
嗨其实这是我同样的问题,但我没有得到任何东西。现在我从特定的Android真实设备(Android Mobile)获得手机号码和他的电子邮件ID。现在有90%的人在Android Mobile上使用什么应用程序应用程序。现在我得到Mobile no和email-ID通过这个什么是应用程序API。它非常简单易用,请参阅下面的代码。
AccountManager am = AccountManager.get(this);
Account[] accounts = am.getAccounts();
for (Account ac : accounts)
{
acname = ac.name;
if (acname.startsWith("91")) {
mobile_no = acname;
}else if(acname.endsWith("@gmail.com")||acname.endsWith("@yahoo.com")||acname.endsWith("@hotmail.com")){
email = acname;
}
// Take your time to look at all available accounts
Log.i("Accounts : ", "Accounts : " + acname);
}
and import this API
并导入此API
import android.accounts.Account;
import android.accounts.AccountManager;
#3
3
I have to make an application which shows the Contact no of the SIM card that is being used in the cell. For that I need to use Telephony Manager class. Can i get details on its usage?
我必须创建一个应用程序,显示单元格中正在使用的SIM卡的联系人号码。为此,我需要使用Telephony Manager类。我能获得有关其用途的详细信息吗?
Yes, You have to use Telephony Manager;If at all you not found the contact no. of user; You can get Sim Serial Number of Sim Card and Imei No. of Android Device by using the same Telephony Manager Class...
是的,你必须使用电话管理器;如果你没有找到联系人号码。用户;您可以使用相同的Telephony Manager Class获取Sim Card的Sim Serial Number和Android Device的Imei No. ...
Add permission:
添加权限:
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
Import:
进口:
import android.telephony.TelephonyManager;
Use the below code:
使用以下代码:
TelephonyManager tm = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
// get IMEI
imei = tm.getDeviceId();
// get SimSerialNumber
simSerialNumber = tm.getSimSerialNumber();
#4
1
Well, all could be temporary hacks, but there is no way to get mobile number of a user. It is against ethical policy.
好吧,一切都可能是暂时的黑客攻击,但没有办法获得用户的手机号码。这违反了道德政策。
For eg, one of the answers above suggests getting all accounts and extracting from there. And it doesn't work anymore! All of these are hacks only.
例如,上面的答案之一建议获取所有帐户并从那里提取。它不再起作用了!所有这些都只是黑客攻击。
Only way to get user's mobile number is going through operator. If you have a tie-up with mobile operators like Aitel, Vodafone, etc, you can get user's mobile number in header of request from mobile handset when connected via mobile network internet.
获取用户手机号码的唯一方法是通过运营商。如果您与Aitel,Vodafone等移动运营商有合作关系,您可以通过移动网络互联网获取移动手机请求标题中的用户手机号码。
Not sure if any manufacturer tie ups to get specific permissions can help - not explored this area, but nothing documented atleast.
不确定是否有任何制造商绑定以获得特定权限可能有所帮助 - 没有探索这个领域,但至少没有任何记录。
#5
0
Sometimes you can retreive the phonenumber with a USSD request to your operator. For example I can get my phonenumber by dialing *116# This can probably be done within an app, I guess, if the USSD responce somehow could be catched. Offcourse this is not a method I would recommend to use within an app that is to be distributed, the code may even differ between operators.
有时您可以通过USSD请求向您的运营商检索电话号码。例如,我可以通过拨打* 116#来获取我的电话号码。这可能是在应用程序中完成的,我想,如果USSD以某种方式响应可能会被捕获。当然,这不是我建议在要分发的应用程序中使用的方法,代码甚至可能在运营商之间有所不同。
#6
-2
As many said:
许多人说:
String phoneNumber = TelephonyManager.getDefault().getLine1Number();
The availability depends strictly on the carrier and the way the number is encoded on the SIM card. If it is hardcoded by the company that makes the SIMs or by the mobile carrier itself. This returns the same as in Settings->about phone.
可用性严格取决于运营商以及SIM卡上编码的方式。如果由制造SIM的公司或移动运营商本身硬编码。返回与设置 - >关于手机相同。
#1
64
You can use the TelephonyManager
to do this:
您可以使用TelephonyManager执行此操作:
TelephonyManager tm = (TelephonyManager)getSystemService(TELEPHONY_SERVICE);
String number = tm.getLine1Number();
The documentation for getLine1Number()
says this method will return null
if the number is "unavailable", but it does not say when the number might be unavailable.
getLine1Number()的文档说如果数字“不可用”,这个方法将返回null,但是它没有说明数字何时可能不可用。
You'll need to give your application permission to make this query by adding the following to your Manifest:
您需要通过向Manifest添加以下内容来授予您的应用程序进行此查询的权限:
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
(You shouldn't use TelephonyManager.getDefault()
to get the TelephonyManager
as that is a private undocumented API call and may change in future.)
(您不应该使用TelephonyManager.getDefault()来获取TelephonyManager,因为这是一个私有的未记录的API调用,并且将来可能会更改。)
#2
6
Hi Actually this is my same question but I didn't get anything.Now I got mobile number and his email-Id from particular Android real device(Android Mobile).Now a days 90% people using what's App application on Android Mobile.And now I am getting Mobile no and email-ID Through this What's app API.Its very simple to use see this below code.
嗨其实这是我同样的问题,但我没有得到任何东西。现在我从特定的Android真实设备(Android Mobile)获得手机号码和他的电子邮件ID。现在有90%的人在Android Mobile上使用什么应用程序应用程序。现在我得到Mobile no和email-ID通过这个什么是应用程序API。它非常简单易用,请参阅下面的代码。
AccountManager am = AccountManager.get(this);
Account[] accounts = am.getAccounts();
for (Account ac : accounts)
{
acname = ac.name;
if (acname.startsWith("91")) {
mobile_no = acname;
}else if(acname.endsWith("@gmail.com")||acname.endsWith("@yahoo.com")||acname.endsWith("@hotmail.com")){
email = acname;
}
// Take your time to look at all available accounts
Log.i("Accounts : ", "Accounts : " + acname);
}
and import this API
并导入此API
import android.accounts.Account;
import android.accounts.AccountManager;
#3
3
I have to make an application which shows the Contact no of the SIM card that is being used in the cell. For that I need to use Telephony Manager class. Can i get details on its usage?
我必须创建一个应用程序,显示单元格中正在使用的SIM卡的联系人号码。为此,我需要使用Telephony Manager类。我能获得有关其用途的详细信息吗?
Yes, You have to use Telephony Manager;If at all you not found the contact no. of user; You can get Sim Serial Number of Sim Card and Imei No. of Android Device by using the same Telephony Manager Class...
是的,你必须使用电话管理器;如果你没有找到联系人号码。用户;您可以使用相同的Telephony Manager Class获取Sim Card的Sim Serial Number和Android Device的Imei No. ...
Add permission:
添加权限:
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
Import:
进口:
import android.telephony.TelephonyManager;
Use the below code:
使用以下代码:
TelephonyManager tm = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
// get IMEI
imei = tm.getDeviceId();
// get SimSerialNumber
simSerialNumber = tm.getSimSerialNumber();
#4
1
Well, all could be temporary hacks, but there is no way to get mobile number of a user. It is against ethical policy.
好吧,一切都可能是暂时的黑客攻击,但没有办法获得用户的手机号码。这违反了道德政策。
For eg, one of the answers above suggests getting all accounts and extracting from there. And it doesn't work anymore! All of these are hacks only.
例如,上面的答案之一建议获取所有帐户并从那里提取。它不再起作用了!所有这些都只是黑客攻击。
Only way to get user's mobile number is going through operator. If you have a tie-up with mobile operators like Aitel, Vodafone, etc, you can get user's mobile number in header of request from mobile handset when connected via mobile network internet.
获取用户手机号码的唯一方法是通过运营商。如果您与Aitel,Vodafone等移动运营商有合作关系,您可以通过移动网络互联网获取移动手机请求标题中的用户手机号码。
Not sure if any manufacturer tie ups to get specific permissions can help - not explored this area, but nothing documented atleast.
不确定是否有任何制造商绑定以获得特定权限可能有所帮助 - 没有探索这个领域,但至少没有任何记录。
#5
0
Sometimes you can retreive the phonenumber with a USSD request to your operator. For example I can get my phonenumber by dialing *116# This can probably be done within an app, I guess, if the USSD responce somehow could be catched. Offcourse this is not a method I would recommend to use within an app that is to be distributed, the code may even differ between operators.
有时您可以通过USSD请求向您的运营商检索电话号码。例如,我可以通过拨打* 116#来获取我的电话号码。这可能是在应用程序中完成的,我想,如果USSD以某种方式响应可能会被捕获。当然,这不是我建议在要分发的应用程序中使用的方法,代码甚至可能在运营商之间有所不同。
#6
-2
As many said:
许多人说:
String phoneNumber = TelephonyManager.getDefault().getLine1Number();
The availability depends strictly on the carrier and the way the number is encoded on the SIM card. If it is hardcoded by the company that makes the SIMs or by the mobile carrier itself. This returns the same as in Settings->about phone.
可用性严格取决于运营商以及SIM卡上编码的方式。如果由制造SIM的公司或移动运营商本身硬编码。返回与设置 - >关于手机相同。