国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

Android 調用發送短信的方法

2019-10-22 18:28:42
字體:
來源:轉載
供稿:網友

Android 調用發送短信的方法

功能:調用發送短信功能

1 、 權限

<uses-permission android:name="android.permission.SEND_SMS"/> 

2、具體實現

Uri smstoUri = Uri.parse("smsto:"); Intent intent = new Intent(Intent.ACTION_VIEW,smstoUri); intent.putExtra("address","電話號碼"); // 沒有電話號碼的話為默認的,即顯示的時候是為空的 intent.putExtra("sms_body","短信內容"); // 設置發送的內容 intent.setType("vnd.android-dir/mms-sms"); startActivity(intent); 

Activity 代碼:

public class MainActivity extends Activity {    private EditText phone ,message;   private Button sendbtn;   protected void onCreate(Bundle savedInstanceState) {     super.onCreate(savedInstanceState);     setContentView(R.layout.activity_main);          phone = (EditText) findViewById(R.id.phone);     message = (EditText) findViewById(R.id.message);     sendbtn = (Button) findViewById(R.id.sendbtn);          //點擊發送短信     sendbtn.setOnClickListener(new OnClickListener() {              public void onClick(View v) {         String p = phone.getText().toString();         String m = message.getText().toString();         Uri smstoUri = Uri.parse("smsto:"); // 解析地址         Intent intent = new Intent(Intent.ACTION_VIEW,smstoUri);         intent.putExtra("address",p); // 沒有電話號碼的話為默認的,即顯示的時候是為空的         intent.putExtra("sms_body",m); // 設置發送的內容         intent.setType("vnd.android-dir/mms-sms");         startActivity(intent);       }     });   } } 

 Mainfest.xml 配置文件:

<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android"   package="com.example.message"   android:versionCode="1"   android:versionName="1.0" >    <uses-sdk     android:minSdkVersion="10"     android:targetSdkVersion="10" />    <application     android:allowBackup="true"     android:icon="@drawable/ic_launcher"     android:label="@string/app_name"     android:theme="@style/AppTheme" >     <activity       android:name="com.example.message.MainActivity"       android:label="@string/app_name" >       <intent-filter>         <action android:name="android.intent.action.MAIN" />          <category android:name="android.intent.category.LAUNCHER" />       </intent-filter>     </activity>   </application>    <!-- 發送短信權限 -->   <uses-permission android:name="android.permission.SEND_SMS" />  </manifest> 

布局示意圖:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"   xmlns:tools="http://schemas.android.com/tools"   android:layout_width="match_parent"   android:layout_height="match_parent"   android:paddingBottom="@dimen/activity_vertical_margin"   android:paddingLeft="@dimen/activity_horizontal_margin"   android:paddingRight="@dimen/activity_horizontal_margin"   android:paddingTop="@dimen/activity_vertical_margin"   tools:context=".MainActivity" >    <EditText     android:id="@+id/phone"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_alignParentLeft="true"     android:layout_alignParentRight="true"     android:ems="10"     android:inputType="number" >      <requestFocus />   </EditText>    <Button     android:id="@+id/sendbtn"     style="?android:attr/buttonStyleSmall"     android:layout_width="150dp"     android:layout_height="50dp"     android:layout_alignParentBottom="true"     android:layout_centerHorizontal="true"     android:layout_marginBottom="28dp"     android:text="Send" />    <EditText     android:id="@+id/message"     android:layout_width="fill_parent"     android:layout_height="wrap_content"     android:layout_above="@+id/sendbtn"     android:layout_alignLeft="@+id/phone"     android:layout_marginBottom="48dp"     android:ems="10" />  </RelativeLayout> 

 以上就是Android 調用短信的方法,如有疑問請留言或者到本站社區交流討論,感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!


注:相關教程知識閱讀請移步到Android開發頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 报价| 台州市| 南充市| 油尖旺区| 菏泽市| 焦作市| 宁武县| 蒙山县| 保德县| 普兰店市| 于都县| 鄂州市| 绵阳市| 通山县| 东阳市| 绥棱县| 刚察县| 合山市| 金沙县| 许昌县| 三穗县| 永新县| 南木林县| 福鼎市| 文山县| 九江县| 陇川县| 汉中市| 奈曼旗| 大名县| 图片| 阿克苏市| 繁峙县| 黑水县| 三门峡市| 普宁市| 合水县| 珲春市| 尖扎县| 皋兰县| 西乌珠穆沁旗|