gpt4 book ai didi

java - 如何从短信收件箱/已发送短信中获取所有者手机号码

转载 作者:行者123 更新时间:2023-12-01 06:16:12 25 4
gpt4 key购买 nike

我已尝试从我的设备的短信收件箱/发件箱中检索所有信息。但我的手机号码,即发件人的手机号码似乎没有被存储。我正在尝试获取此号码,以便我可以从发件箱捕获手机号码,并允许用户使用它在我的应用程序上注册,认为它接近用户在设备上使用的准确手机号码。这样他们就不必在我的应用程序中输入手机号码进行注册。

请告诉我是否有任何方法可以从短信收件箱/发送中找到手机号码

代码在这里:

public void readSMS (Activity MainActivity) 
{
Uri inSMSUri = Uri.parse ("content://sms/inbox");
System.out.println ( "the URI :: " + inSMSUri);

Cursor c = MainActivity.getContentResolver().query(inSMSUri, null, null, null, "date desc");
if (c!= null)
{

StringBuilder sb = new StringBuilder ();
while (c.moveToNext ()) {
System.out.println ("content:" + c.getString (c.getColumnIndex ("body")));

for(int i=0; i<c.getColumnCount();i++)
{
System.out.println("SMS:INBOX: c getColumnName(i):: "+c.getColumnName(i) +
" c.getString(i):: "+c.getString(i));
}

}
c.close ();


Uri outSMSUri = Uri.parse ("content://sms/sent");

c = MainActivity.getContentResolver().query(outSMSUri, null, null, null, "date desc");
if (c!= null)
{

while (c.moveToNext ()) {
System.out.println ("content:" + c.getString (c.getColumnIndex ("body")));

for(int i=0; i<c.getColumnCount();i++)
{
System.out.println("SMS:SENT: c getColumnName(i):: "+c.getColumnName(i) +
" c.getString(i):: "+c.getString(i));
}

}

}

}
}

但未找到 SENDER 手机号码列:

SMS INBOX 正在生成此输出:

content:Hello! You are roaming on Vodafone Maharashtra

SMS:INBOX: c getColumnName(i):: _id c.getString(i):: 9

SMS:INBOX: c getColumnName(i):: thread_id c.getString(i):: 3

SMS:INBOX: c getColumnName(i):: address c.getString(i):: VM-VDFONE

SMS:INBOX: c getColumnName(i):: m_size c.getString(i):: 297

SMS:INBOX: c getColumnName(i):: person c.getString(i):: 0

SMS:INBOX: c getColumnName(i):: date c.getString(i):: 1381599923412

SMS:INBOX: c getColumnName(i):: date_sent c.getString(i):: 1381599913000

SMS:INBOX: c getColumnName(i):: protocol c.getString(i):: 0

SMS:INBOX: c getColumnName(i):: read c.getString(i):: 1

SMS:INBOX: c getColumnName(i):: status c.getString(i):: -1

SMS:INBOX: c getColumnName(i):: type c.getString(i):: 1

SMS:INBOX: c getColumnName(i):: reply_path_present c.getString(i):: 0

SMS:INBOX: c getColumnName(i):: subject c.getString(i):: null

SMS:INBOX: c getColumnName(i):: body c.getString(i):: Hello! You are roaming on Vodafone Maharashtra

SMS:INBOX: c getColumnName(i):: service_center c.getString(i):: +919820005556

SMS:INBOX: c getColumnName(i):: locked c.getString(i):: 0

SMS:INBOX: c getColumnName(i):: sim_id c.getString(i):: 1

SMS:INBOX: c getColumnName(i):: error_code c.getString(i):: 0

SMS:INBOX: c getColumnName(i):: seen c.getString(i):: 1

SMS:INBOX: c getColumnName(i):: ipmsg_id c.getString(i):: 0

But SENDER Mobile number column NOT found:

SMS:SENT: c getColumnName(i):: _id c.getString(i):: 1783

SMS:SENT: c getColumnName(i):: thread_id c.getString(i):: 26

SMS:SENT: c getColumnName(i):: address c.getString(i):: 1909

SMS:SENT: c getColumnName(i):: m_size c.getString(i):: null

SMS:SENT: c getColumnName(i):: person c.getString(i):: 0

SMS:SENT: c getColumnName(i):: date c.getString(i):: 1394009796560

SMS:SENT: c getColumnName(i):: error_code c.getString(i):: 0

SMS:SENT: c getColumnName(i):: seen c.getString(i):: 1

SMS:SENT: c getColumnName(i):: ipmsg_id c.getString(i):: 0

SMS:SENT: c getColumnName(i):: m_size c.getString(i):: 21

SMS:SENT: c getColumnName(i):: person c.getString(i):: 0

SMS:SENT: c getColumnName(i):: date c.getString(i):: 1392004530098

SMS:SENT: c getColumnName(i):: date_sent c.getString(i):: 0

SMS:SENT: c getColumnName(i):: protocol c.getString(i):: null

SMS:SENT: c getColumnName(i):: read c.getString(i):: 1

SMS:SENT: c getColumnName(i):: status c.getString(i):: -1

SMS:SENT: c getColumnName(i):: type c.getString(i):: 2

SMS:SENT: c getColumnName(i):: reply_path_present c.getString(i):: null

SMS:SENT: c getColumnName(i):: subject c.getString(i):: null

SMS:SENT: c getColumnName(i):: body c.getString(i):: Take care

SMS:SENT: c getColumnName(i):: service_center c.getString(i):: null

SMS:SENT: c getColumnName(i):: locked c.getString(i):: 0

SMS:SENT: c getColumnName(i):: sim_id c.getString(i):: 1

SMS:SENT: c getColumnName(i):: error_code c.getString(i):: 0

SMS:SENT: c getColumnName(i):: ipmsg_id c.getString(i):: 0

最佳答案

您可以尝试以下方式获取手机号码:

  1. TelephonyManager - 不适用于大多数号码 TelephonyManager telephonyManager = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE); 最终字符串 contactNumber = telephonyManager.getLine1Number();

  2. AccountManager - 从 WhatsApp 和 Telegram 等帐户获取号码AccountManager accountManager = AccountManager.get(context); Account[] 账户 = accountManager.getAccounts(); String 联系人号码 = null; if (accounts.length > 0) { for(帐户帐户:帐户){ if ("com.whatsapp".equals(acc.type)) { if (!acc.name.matches(".[a-zA-Z]+.")) { 联系人号码 = acc.name; } } if (contactNumber == null && "org.telegram.messenger.account".equals(acc.type)) { if (!acc.name.matches(".[a-zA-Z]+.")) { 联系人号码 = acc.name; } } } }

  3. 与短信 API 集成,如 https://www.twilio.com/询问用户号码并向用户号码发送带有验证码的短信。要么要求用户输入身份验证码,要么应用程序可以直接读取传入消息,解析身份验证码并进行验证。它可能不适用于印度的完整 DND 注册号码。

  4. 未接来电!!!与 http://dial2verify.in/ 等服务集成向用户询问电话号码,调用 dial2verify 会返回一个电话号码,要求用户对该号码进行未接来电。收到未接来电后,dial2verify 将向您的服务器发起调用,并提供验证号码详细信息。

关于java - 如何从短信收件箱/已发送短信中获取所有者手机号码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23946071/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com