我想通过意图发送短信,但是当我使用此代码时,它会将我重定向到错误的联系人:

Intent intentt = new Intent(Intent.ACTION_VIEW);

intentt.setData(Uri.parse("sms:"));

intentt.setType("vnd.android-dir/mms-sms");

intentt.putExtra(Intent.EXTRA_TEXT, "");

intentt.putExtra("address", phone number);

context.startActivity(intentt);

为什么?

此外,我知道一种方法来跟踪短信发送,但我不知道如何编码:

Starting activity: Intent {

act=android.intent.action.SENDTO dat=smsto:%2B**XXXXXXXXXXXX** flg=0x14000000

cmp=com.android.mms/.ui.ComposeMessageActivity }

其中XXXXXXXXXXXX是电话号码.

解决方法:

我从一个博客开发了这个功能.您可以通过两种方式发送短信.

>打开本机短信作曲家

>编写您的消息并从您的Android应用程序发送

这是第一种方法的代码.

main.xml中

android:id="@+id/relativeLayout1"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

xmlns:android="http://schemas.android.com/apk/res/android">

android:id="@+id/btnSendSMS"

android:layout_height="wrap_content"

android:layout_width="wrap_content"

android:text="Send SMS"

android:layout_centerInParent="true"

android:onClick="sendSMS">

活动

public class SendSMSActivity extends Activity {

/** Called when the activity is first created. */

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

}

public void sendSMS(View v)

{

String number = "12346556"; // The number on which you want to send SMS

startActivity(new Intent(Intent.ACTION_VIEW, Uri.fromParts("sms", number, null)));

}

/* or

public void sendSMS(View v)

{

Uri uri = Uri.parse("smsto:12346556");

Intent it = new Intent(Intent.ACTION_SENDTO, uri);

it.putExtra("sms_body", "Here you can set the SMS text to be sent");

startActivity(it);

} */

}

注意:-

在此方法中,您不需要AndroidManifest.xml文件中的SEND_SMS权限.

对于第二种方法,请参阅此BLOG.您将从此处找到一个很好的解释.

希望对你有帮助…

标签:android,sms,android-intent

来源: https://codeday.me/bug/20190917/1809203.html

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐