Android中实现短信发送的一种方式
2017-09-23 20:51
363 查看
代码是小马写的,我只是借来用用~(@^_^@)~
在此基础上可以实现以下功能:
发送特定指令到指定对象
实现短信群发
定时自动发送信息
SendSmsActivity.java:
AndroidMainfest.xml:
activity_send_sms.xml:
实现效果:
在此基础上可以实现以下功能:
发送特定指令到指定对象
实现短信群发
定时自动发送信息
SendSmsActivity.java:
package com.test.smsmangerdemo.sendsmsactivity; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.content.Intent; import android.app.PendingIntent; import android.telephony.SmsManager; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.Toast; /** *发送短信实例 */ public class SendSmsActivity extends AppCompatActivity { EditText phone, content; Button send; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_send_sms); //获取 SMSManger管理器 final SmsManager smsManager = SmsManager.getDefault(); //初始化控件 phone = (EditText) findViewById(R.id.et_phone); content = (EditText) findViewById(R.id.et_content); send = (Button) findViewById(R.id.btn_send); send.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //创建一个 android.app.PendingIntent 对象 PendingIntent pi = PendingIntent.getActivity(SendSmsActivity.this, 0, new Intent(), 0); //发送短信 smsManager.sendTextMessage(phone.getText().toString(), null, content.getText().toString(), pi, null); //提示短信发送完成 Toast.makeText(SendSmsActivity.this, "短信发送完成", Toast.LENGTH_SHORT).show(); } }); } }
AndroidMainfest.xml:
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.test.smsmangerdemo.sendsmsactivity" > <uses-permission android:name="android.permission.SEND_SMS"/> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/AppTheme" > <activity android:name=".SendSmsActivity" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest>
activity_send_sms.xml:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout 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:orientation="vertical" tools:context="com.test.smsmangerdemo.sendsmsactivity.SendSmsActivity"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="收件人"/> <EditText android:id="@+id/et_phone" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="10dp"/> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="10dp" android:orie afde ntation="horizontal"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="发送内容"/> <EditText android:id="@+id/et_content" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="10dp" android:gravity="top" android:lines="5" android:text="你好"/> </LinearLayout> <Button android:layout_gravity="center_horizontal" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="发送" android:id="@+id/btn_send" /> </LinearLayout>
实现效果:
相关文章推荐
- android两种方式实现发送短信的功能代码
- Android - 批量发送短信的实现方式
- android中拨打电话和短信发送的实现
- android 联动listview 的一种不太健康的实现方式
- 实现OWA 2010通过短信方式发送邮件提醒功能
- 实现OWA 2010通过短信方式发送邮件提醒功能
- Android如何实现后台发送短信
- Android-->发送短信页面实现(短信发送以及群发和从电话本中选择联系人)-----------》2
- android 发送短信的两种方式,以及接收报告和发送报告
- Android学习第十四天----发送短信的两种方式
- Android实现拨打电话、发送短信和发送邮件功能
- Android 实现发送短信demo
- android实现发送短信demo
- Android发送短信,并监听短信发送后是否发送成功的实现方法
- Android小程序:实现发送短信
- Android短信的发送和广播接收者实现短信的监听
- android实现发送短信并保存到数据库,同时可以获得发送报告和接收报告
- 举例说明android中SmsManager的用法---用来实现手机发送短信的功能
- android实现发送短信的功能
- Android学习之1:实现发送短信功能