如何从SMS收件箱/已发送中获取所有者的手机号码 [英] How to Fetch Owner Mobile number from SMS Inbox/Sent
问题描述
我试图从设备的SMS收件箱/发件箱中检索所有信息.但是我的手机号码(即发件人的手机号码)似乎没有存储.我正在尝试获取此号码,以便我可以从发件箱"中捕获手机号码,并允许用户使用它在我的App上注册,因为它接近用户在设备上使用的准确手机号码.这样一来,他们不必在我的应用程序中键入手机即可进行注册.
I have tried to retrieve all information from SMS Inbox/Outbox of my device. But my mobile number i.e. Sender's mobile number does not seem to be stored. I am trying to get this number so that I can capture mobile number from the OUTBOX and allow user to use it to register on my App, considering it to be near accurate mobile number that the user is using on the device. So that they don't have to type the mobile in my app for registration.
请告知我是否可以通过SMS INBOX/SENT查找手机号码
Please let me know if there is any way to find mobile number from the SMS INBOX/SENT
此处的代码:
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手机号码列:
But SENDER Mobile number column NOT found:
SMS INBOX正在生成以下输出:
SMS INBOX is generating this output:
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
推荐答案
您可以尝试以下方法获取手机号码:
You can try the following ways to get the mobile number:
-
TelephonyManager-不适用于大多数号码 TelephonyManager telephonyManager =(TelephonyManager)this.getSystemService(Context.TELEPHONY_SERVICE); 最终字符串contactNumber = telephonyManager.getLine1Number();
TelephonyManager - Will not work for most of the numbers TelephonyManager telephonyManager = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE); final String contactNumber = telephonyManager.getLine1Number();
AccountManager-从类似WhatsApp和Telegram的帐户中获取号码 AccountManager accountManager = AccountManager.get(context); Account []个帐户= accountManager.getAccounts(); 字符串contactNumber = null; 如果(accounts.length> 0){ 对于(Account acc:account){ 如果("com.whatsapp" .equals(acc.type)){ if(!acc.name.matches(. [a-zA-Z] +.")){ contactNumber =帐户名称; } } if(contactNumber == null&"org.telegram.messenger.account" .equals(acc.type)){ if(!acc.name.matches(. [a-zA-Z] +.")){ contactNumber =帐户名称; } } } }
AccountManager - Fetch number from accounts like WhatsApp and Telegram AccountManager accountManager = AccountManager.get(context); Account[] accounts = accountManager.getAccounts(); String contactNumber = null; if (accounts.length > 0) { for (Account acc : accounts) { if ("com.whatsapp".equals(acc.type)) { if (!acc.name.matches(".[a-zA-Z]+.")) { contactNumber = acc.name; } } if (contactNumber == null && "org.telegram.messenger.account".equals(acc.type)) { if (!acc.name.matches(".[a-zA-Z]+.")) { contactNumber = acc.name; } } } }
与Sms API集成,例如 https://www.twilio.com/ 向用户询问号码,并通过一些验证码将短信发送到用户的号码.要求用户输入验证码,或者应用程序可以直接读取传入的消息,解析验证码并进行验证. 它可能不适用于来自印度的完整DND注册号码.
Integrate with Sms API like https://www.twilio.com/ Ask user for number and send sms to the user's number with some authentication code. Either ask user to input the authentication code or the app can directly read the incoming message, parse the authentication code and validate. It might not work with full DND registered numbers from India.
这篇关于如何从SMS收件箱/已发送中获取所有者的手机号码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!