通过故意发送短信 [英] Send SMS via intent

查看:180
本文介绍了通过故意发送短信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过故意发送短信,但是当我用这个code,它重定向我错了,请联系:

I want to send an SMS via intent, but when I use this code, it redirects me to wrong contact:

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);

为什么呢?另外,我知道的方式效仿短信发送,但我不知道该怎么code这样的:

Why? Also, I know a way to follow SMS sending, but I do not know how code this:

Starting activity: Intent { 
   act=android.intent.action.SENDTO dat=smsto:%2B**XXXXXXXXXXXX** flg=0x14000000    
   cmp=com.android.mms/.ui.ComposeMessageActivity }

其中,XXXXXXXXXXXX是电话号码。

where XXXXXXXXXXXX is phone number.

推荐答案

我已经开发了从一个博客此功能。有2种方式,你可以发送短信。

I have developed this functionality from one Blog. There are 2 ways you can send sms.

  1. 开启本机短信作曲家
  2. 在编写并发送信息,从Android应用程序

这是第一个方法code。

的main.xml

<?xml version="1.0" encoding="utf-8"?>  
    <RelativeLayout  
        android:id="@+id/relativeLayout1"  
        android:layout_width="fill_parent"  
        android:layout_height="fill_parent"  
        xmlns:android="http://schemas.android.com/apk/res/android">  

            <Button  
                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">  
           </Button>  
   </RelativeLayout>

活动

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权限。

NOTE:- In this method, you doesn’t require SEND_SMS permission inside the AndroidManifest.xml file.

有关第二个方法,请参阅本博客。你会发现很好的解释从这里开始。

For 2nd method refer this BLOG. You will find good explanation from here.

希望这会帮助你......

Hope this will help you...

这篇关于通过故意发送短信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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