如何获取真实设备中当前SIM卡的手机号码?

发布于 2024-08-20 08:05:22 字数 93 浏览 4 评论 0原文

我必须提交一份申请,显示小区中使用的 SIM 卡的联系号码。为此,我需要使用 TelephonyManager 类。我可以获得其使用的详细信息吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

梦魇绽荼蘼 2024-08-27 08:05:22

您可以使用 TelephonyManager 来执行此操作:

TelephonyManager tm = (TelephonyManager)getSystemService(TELEPHONY_SERVICE); 
String number = tm.getLine1Number();

getLine1Number()<的文档/code>表示如果号码“不可用”,此方法将返回 null,但它没有说明该号码何时可能不可用。

您需要授予应用程序 进行此查询的权限 通过将以下内容添加到清单中:(

<uses-permission android:name="android.permission.READ_PHONE_STATE"/>

您不应使用 TelephonyManager.getDefault() 来获取 TelephonyManager 作为 这是一个未记录的私有 API 调用,将来可能会更改。)

You can use the TelephonyManager to do this:

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.

You'll need to give your application permission to make this query by adding the following to your 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.)

偏闹i 2024-08-27 08:05:22

嗨,实际上这是我同样的问题,但我没有得到任何信息。现在我从特定的 Android 真实设备(Android 手机)获得了手机号码和他的电子邮件 ID。现在 90% 的人在 Android 手机上使用什么应用程序。并且现在我通过 What's app API 获取手机号码和电子邮件 ID。使用起来非常简单,请参阅下面的代码。

            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);
    }

并导入这个API

    import android.accounts.Account;
    import android.accounts.AccountManager;

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.

            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

    import android.accounts.Account;
    import android.accounts.AccountManager;
灯角 2024-08-27 08:05:22

我必须制作一个应用程序,显示小区中使用的 SIM 卡的联系号码。为此,我需要使用电话管理器类。我可以获得其使用的详细信息吗?

是的,
您必须使用电话管理器;如果您根本找不到联系号码。用户的;
您可以使用相同的 Telephony Manager 类获取 Sim 卡的 Sim 序列号和 Android 设备的 Imei 号码...

添加权限:

<uses-permission android:name="android.permission.READ_PHONE_STATE"/>

导入:

import android.telephony.TelephonyManager;

使用以下代码:

TelephonyManager tm = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);

         // get IMEI
         imei = tm.getDeviceId();

         // get SimSerialNumber
         simSerialNumber = tm.getSimSerialNumber();

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?

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...

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();
一笑百媚生 2024-08-27 08:05:22

好吧,所有这些都可能是临时黑客,但没有办法获取用户的手机号码。这是违反道德政策的。

例如,上面的答案之一建议获取所有帐户并从那里提取。而且它不再起作用了!
所有这些都只是黑客行为。

获取用户手机号码的唯一方法是通过运营商。如果您与 Aitel、Vodafone 等移动运营商有合作,当通过移动网络互联网连接时,您可以在移动手机的请求标头中获取用户的手机号码。

不确定是否有任何制造商联手获得特定许可可以提供帮助 - 没有探索这个领域,但至少没有任何记录。

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.

Not sure if any manufacturer tie ups to get specific permissions can help - not explored this area, but nothing documented atleast.

怎会甘心 2024-08-27 08:05:22

有时,您可以通过向运营商发出 USSD 请求来检索电话号码。
例如我可以通过拨打 *116# 获取我的电话号码
我想,如果可以以某种方式捕获 USSD 响应,这可能可以在应用程序内完成。
当然,这不是我建议在要分发的应用程序中使用的方法,代码甚至可能在运营商之间有所不同。

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.

┼── 2024-08-27 08:05:22

正如许多人所说:

String phoneNumber = TelephonyManager.getDefault().getLine1Number();

可用性严格取决于运营商以及 SIM 卡上的号码编码方式。如果它是由制造 SIM 卡的公司或移动运营商本身进行硬编码的。这与“设置”->“关于手机”中的返回内容相同。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文