我想在我的应用中添加短信发送功能,并且还想要用户可以直接从应用程序中选择联系人列表中的联系人的选项。是否可以将联系人列表与我的应用程序集成。
由于
答案 0 :(得分:44)
答案 1 :(得分:13)
以下是有关如何将联系人加载到您的应用中的信息的链接: http://developer.android.com/guide/topics/providers/content-providers.html
希望这是你正在寻找的。 p>
答案 2 :(得分:7)
尝试使用本教程发送短信。希望这会有所帮助。
http://www.tutorialspoint.com/android/android_sending_sms.htm
在活动文件中添加以下方法,您需要在其中实现“发送短信”功能。
protected void sendSMSMessage() {
String phoneNo = txtphoneNo.getText().toString();
String message = txtMessage.getText().toString();
try {
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(phoneNo, null, message, null, null);
Toast.makeText(getApplicationContext(), "SMS sent.",
Toast.LENGTH_LONG).show();
} catch (Exception e) {
Toast.makeText(getApplicationContext(),
"SMS faild, please try again.",
Toast.LENGTH_LONG).show();
e.printStackTrace();
}
}
您需要导入 android.telephony.SmsManager 以实现sendSMSMessage方法。
在活动的xml布局中添加一个按钮,并在Button click事件上调用sendSMSMessage方法。
Button.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
sendSMSMessage();
}
});
在Manifest.xml中添加以下权限。
<uses-permission android:name="android.permission.SEND_SMS"/>