从联系人的角度来看,如何将联系人号码发送到我的短信应用程序,以及如何向其发送短信 [英] From a contact view, how to send a contact number to my sms app, to send an sms to it

查看:107
本文介绍了从联系人的角度来看,如何将联系人号码发送到我的短信应用程序,以及如何向其发送短信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我构建了一个短信应用程序,该应用程序支持短信活动的所有功能(仅短信)。但是现在,我的问题是,当我的应用程序已经是短信的默认设置时,当我想通过我的应用程序向其发送短信时,无法从联系人视图中获取该号码。这是解释我想要实现的图像。 当我单击短信图标时,我的应用已打开,我无法获取该号码
我没有任何代码来处理活动中的SEND / SENDTO操作,但我只是在清单文件中提到了intent-filter:action.SEND,action.SENDTO,因为如果我们必须希望将应用程序选择为默认的短信应用程序。我以为可以从onActivityResult访问联系人视图中的号码,但它似乎不起作用,请帮忙!

I've built an sms app wich support all features for sms activities(only sms). But now, my problem is that when my app is already the default one for sms, I can't get the number from contact view when I'd like to send sms to it through my app. Here are images to explain what I'd like to achieve.! When I click to the sms icon,my app is opened by I can't get the number I do not have any code to handle the action SEND/SENDTO in my activity, but I just mentioned the intent-filter:action.SEND, action.SENDTO in the manifest file, as it is obligatory if we want to make the app selectable as the default sms app. I thought that the number from the contact view is accessed from the onActivityResult but it seems to not work, please help!

推荐答案

何时从通讯录中获取 SENDTO ,该数字-可能是多个数字-将作为 Uri 上的数据附加在意图启动了​​您的活动。初始化活动时,请检查相应的操作,并在必要时检索编号。

When getting a SENDTO from Contacts, the number - possibly multiple numbers - will be attached as the data Uri on the Intent that started your Activity. When initializing your Activity, check for the appropriate action, and retrieve the number(s) if necessary.

一个基本示例:

if (Intent.ACTION_SENDTO.equals(getIntent().getAction())) {
    Uri data = getIntent().getData();
    String numbers = data.getSchemeSpecificPart();
}

为实现更可靠的实现,谨慎地删除任何其他参数可能在 Uri 上,并替换所有非拉丁数字。

For a more solid implementation, it would be prudent to strip any additional parameters that might be on the Uri, and to replace any non-Latin digits.

if (Intent.ACTION_SENDTO.equals(getIntent().getAction())) {
    Uri data = getIntent().getData();
    String numbers = data.getSchemeSpecificPart();

    // Strip any extraneous parameters
    int i = numbers.indexOf('?');
    numbers = (i == -1) ? numbers : numbers.substring(0, i);

    // Replace non-Latin digits, and ensure our delimiter is something we expect
    numbers = PhoneNumberUtils.replaceUnicodeDigits(numbers).replace(",", ";");
    ...
}

如果收到多个数字,则应该以逗号或分号分隔的 String 。以上内容用分号替换了逗号,因此我们以后不必担心使用了哪个。然后,您可以简单地 split() 数字来获取单个数字,如果您收到的不止一个。

If multiple numbers are received, they should come in a comma- or semicolon-delimited String. The above replaces commas with semicolons, so we don't need to worry later about which was used. You can then simply split() the numbers to get the individual numbers, should you've received more than one.

这篇关于从联系人的角度来看,如何将联系人号码发送到我的短信应用程序,以及如何向其发送短信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆