在Android中发送短信和彩信,监听短信并显示
来源:互联网 发布:python xpath 解析网页 编辑:程序博客网 时间:2024/05/16 09:22
发送短信:
String body="this is sms demo";
Intent mmsintent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("smsto", number, null));
mmsintent.putExtra(Messaging.KEY_ACTION_SENDTO_MESSAGE_BODY, body);
mmsintent.putExtra(Messaging.KEY_ACTION_SENDTO_COMPOSE_MODE, true);
mmsintent.putExtra(Messaging.KEY_ACTION_SENDTO_EXIT_ON_SENT, true);
startActivity(mmsintent);
发送彩信:
StringBuilder sb = new StringBuilder();
sb.append("file://");
sb.append(fd.getAbsoluteFile());
Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mmsto", number, null));
// Below extra datas are all optional.
intent.putExtra(Messaging.KEY_ACTION_SENDTO_MESSAGE_SUBJECT, subject);
intent.putExtra(Messaging.KEY_ACTION_SENDTO_MESSAGE_BODY, body);
intent.putExtra(Messaging.KEY_ACTION_SENDTO_CONTENT_URI, sb.toString());
intent.putExtra(Messaging.KEY_ACTION_SENDTO_COMPOSE_MODE, composeMode);
intent.putExtra(Messaging.KEY_ACTION_SENDTO_EXIT_ON_SENT, exitOnSent);
startActivity(intent);
广播监听短信并显示内容:
AndroidManifest.xml中添加
<receiver android:name=".receive">
<intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
<uses-permission android:name="android.permission.RECEIVE_SMS"></uses-permission>
<uses-permission android:name="android.permission.READ_SMS"></uses-permission>
再写一个广播监听
public class receive extends BroadcastReceiver
{
String receiveMsg = "";
public void onReceive(Context context, Intent intent)
{
SmsMessage[] msg= null;
if (intent.getAction().equals("android.provider.Telephony.SMS_RECEIVED"))
{
//StringBuilder buf = new StringBuilder();
Bundle bundle = intent.getExtras();
if (bundle != null) {
Object[] pdusObj = (Object[]) bundle.get("pdus");
msg= new SmsMessage[pdusObj.length];
for (int i = 0; i<pdusObj.length; i++)
msg[i] = SmsMessage.createFromPdu ((byte[]) pdusObj[i]);
}
for(int i = 0; i < msg.length; i++)
{
String msgTxt = msg[i].getMessageBody();
if (msgTxt.equals("Testing!"))
{
Toast.makeText(context, "success!", Toast.LENGTH_LONG).show();
return;
}
else
{
Toast.makeText(context, msgTxt, Toast.LENGTH_LONG).show();
return;
}
}
return;
}
}
- 在Android中发送短信和彩信,监听短信并显示
- 在Android中发送短信和彩信,监听短信并显示
- 在Android中发送短信和彩信
- Android中发送短信和彩信
- Android中发送短信和彩信
- 监听短信和彩信
- Android中短信的收发机制 发送短信 接收短信 拦截短信 监听短信
- Android监听发送短信
- Opera书签在短信或者彩信文本中发送
- android广播监听短信并显示内容
- android广播监听短信并显示内容
- android广播监听短信并显示内容
- 发送并监听短信状态
- Android监听发送短信和接受短信的事件
- android广播监听接收和发送短信
- 安卓短信功能全解:调用系统短信功能发送短信、彩信,使用SmsManager发送短信,并监听发送短信的投递情况,使用广播接收器监听接收的短信。
- android 发送短信,彩信,邮件代码
- 在程序中发送短信,并写入短信数据库
- 递归求斐波拉数列函数
- 工程免发布 和 debug远程服务器
- 使用CodeSmith4.0针对中文会有乱码问题
- sscanf
- Android上监听收到的短信(SMS)
- 在Android中发送短信和彩信,监听短信并显示
- Android中彩信文件的读取
- Android中短信相关信息的数据库
- 关于ASP.NET AJAX中的TabContainer的样式
- 解析Android中的main线程与子线程
- 请教cassandra中hector操作SuperColumn的例子,谢谢!
- SMS管理:收信箱 发信息 编写新信息
- DTO Entity ActionFrom View
- 工厂方法模式