- 浏览: 23358 次
- 性别:
- 来自: 北京
最新评论
public class EX06_05SMSreceiver extends BroadcastReceiver
{
/*
* 声明静态字符串,并使用
* android.provider.Telephony.SMS_RECEIVED
* 作为Action为短信的依据
*/
private static final String mACTION =
"android.provider.Telephony.SMS_RECEIVED";
private String str_receive="收到短信!";
@Override
public void onReceive(Context context, Intent intent)
{
// TODO Auto-generated method stub
Toast.makeText(context, str_receive.toString(),
Toast.LENGTH_LONG).show();
/*判断传来Intent是否为短信*/
if (intent.getAction().equals(mACTION))
{
/*建构一字符串集合变量sb*/
StringBuilder sb = new StringBuilder();
/*接收由Intent传来的数据*/
Bundle bundle = intent.getExtras();
/*判断Intent是有数据*/
if (bundle != null)
{
/* pdus为 android内置短信参数 identifier
* 通过bundle.get("")返回一包含pdus的对象*/
Object[] myOBJpdus = (Object[]) bundle.get("pdus");
/*构造短信对象array,并依据收到的对象长度来创建array的大小*/
SmsMessage[] messages = new SmsMessage[myOBJpdus.length];
for (int i = 0; i<myOBJpdus.length; i++)
{
messages[i] =
SmsMessage.createFromPdu((byte[]) myOBJpdus[i]);
}
/* 将送来的短信合并自定义信息于StringBuilder当中 */
for (SmsMessage currentMessage : messages)
{
sb.append("接收到来自:\n");
/* 收信人的电话号码 */
sb.append(currentMessage.getDisplayOriginatingAddress());
sb.append("\n------传来的短信------\n");
/* 取得传来信息的BODY */
sb.append(currentMessage.getDisplayMessageBody());
Toast.makeText
(
context, sb.toString(), Toast.LENGTH_LONG
).show();
}
}
/* 以Notification(Toase)显示来讯信息 */
Toast.makeText
(
context, sb.toString(), Toast.LENGTH_LONG
).show();
/* 返回主Activity */
Intent i = new Intent(context, EX06_05.class);
/*自定义一Bundle*/
Bundle mbundle = new Bundle();
/*将短信信息以putString()方法存入自定义的bundle内*/
mbundle.putString("STR_INPUT", sb.toString());
/*将自定义bundle写入Intent中*/
i.putExtras(mbundle);
/*设置Intent的Flag以一个全新的task来运行*/
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}
}
}
收到消息后要返回到的主activity
public class EX06_05 extends Activity
{
/*声明一个TextView,String数组与两个文本字符串变量*/
private TextView mTextView1;
public String[] strEmailReciver;
public String strEmailSubject;
public String strEmailBody;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
/*通过findViewById构造器创建TextView对象*/
mTextView1 = (TextView) findViewById(R.id.myTextView1);
mTextView1.setText("等待接收短信...");
try
{
/*取得短信传来的bundle*/
Bundle bunde = this.getIntent().getExtras();
if (bunde!= null)
{
/*将bunde内的字符串取出*/
String sb = bunde.getString("STR_INPUT");
/*自定义一Intent来运行寄送E-mail的工作*/
Intent mEmailIntent =
new Intent(android.content.Intent.ACTION_SEND);
/*设置邮件格式为"plain/text"*/
mEmailIntent.setType("plain/text");
/*
* 取得EditText01,02,03,04的值作为
* 收件人地址,附件,主题,正文
*/
strEmailReciver =new String[]{"jay.mingchieh@gmail.com"};
strEmailSubject = "你有一封短信!!";
strEmailBody = sb.toString();
/*将取得的字符串放入mEmailIntent中*/
mEmailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,
strEmailReciver);
mEmailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,
strEmailSubject);
mEmailIntent.putExtra(android.content.Intent.EXTRA_TEXT,
strEmailBody);
startActivity(Intent.createChooser(mEmailIntent,
getResources().getString(R.string.str_message)));
}
else
{
finish();
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
{
/*
* 声明静态字符串,并使用
* android.provider.Telephony.SMS_RECEIVED
* 作为Action为短信的依据
*/
private static final String mACTION =
"android.provider.Telephony.SMS_RECEIVED";
private String str_receive="收到短信!";
@Override
public void onReceive(Context context, Intent intent)
{
// TODO Auto-generated method stub
Toast.makeText(context, str_receive.toString(),
Toast.LENGTH_LONG).show();
/*判断传来Intent是否为短信*/
if (intent.getAction().equals(mACTION))
{
/*建构一字符串集合变量sb*/
StringBuilder sb = new StringBuilder();
/*接收由Intent传来的数据*/
Bundle bundle = intent.getExtras();
/*判断Intent是有数据*/
if (bundle != null)
{
/* pdus为 android内置短信参数 identifier
* 通过bundle.get("")返回一包含pdus的对象*/
Object[] myOBJpdus = (Object[]) bundle.get("pdus");
/*构造短信对象array,并依据收到的对象长度来创建array的大小*/
SmsMessage[] messages = new SmsMessage[myOBJpdus.length];
for (int i = 0; i<myOBJpdus.length; i++)
{
messages[i] =
SmsMessage.createFromPdu((byte[]) myOBJpdus[i]);
}
/* 将送来的短信合并自定义信息于StringBuilder当中 */
for (SmsMessage currentMessage : messages)
{
sb.append("接收到来自:\n");
/* 收信人的电话号码 */
sb.append(currentMessage.getDisplayOriginatingAddress());
sb.append("\n------传来的短信------\n");
/* 取得传来信息的BODY */
sb.append(currentMessage.getDisplayMessageBody());
Toast.makeText
(
context, sb.toString(), Toast.LENGTH_LONG
).show();
}
}
/* 以Notification(Toase)显示来讯信息 */
Toast.makeText
(
context, sb.toString(), Toast.LENGTH_LONG
).show();
/* 返回主Activity */
Intent i = new Intent(context, EX06_05.class);
/*自定义一Bundle*/
Bundle mbundle = new Bundle();
/*将短信信息以putString()方法存入自定义的bundle内*/
mbundle.putString("STR_INPUT", sb.toString());
/*将自定义bundle写入Intent中*/
i.putExtras(mbundle);
/*设置Intent的Flag以一个全新的task来运行*/
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}
}
}
收到消息后要返回到的主activity
public class EX06_05 extends Activity
{
/*声明一个TextView,String数组与两个文本字符串变量*/
private TextView mTextView1;
public String[] strEmailReciver;
public String strEmailSubject;
public String strEmailBody;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
/*通过findViewById构造器创建TextView对象*/
mTextView1 = (TextView) findViewById(R.id.myTextView1);
mTextView1.setText("等待接收短信...");
try
{
/*取得短信传来的bundle*/
Bundle bunde = this.getIntent().getExtras();
if (bunde!= null)
{
/*将bunde内的字符串取出*/
String sb = bunde.getString("STR_INPUT");
/*自定义一Intent来运行寄送E-mail的工作*/
Intent mEmailIntent =
new Intent(android.content.Intent.ACTION_SEND);
/*设置邮件格式为"plain/text"*/
mEmailIntent.setType("plain/text");
/*
* 取得EditText01,02,03,04的值作为
* 收件人地址,附件,主题,正文
*/
strEmailReciver =new String[]{"jay.mingchieh@gmail.com"};
strEmailSubject = "你有一封短信!!";
strEmailBody = sb.toString();
/*将取得的字符串放入mEmailIntent中*/
mEmailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,
strEmailReciver);
mEmailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,
strEmailSubject);
mEmailIntent.putExtra(android.content.Intent.EXTRA_TEXT,
strEmailBody);
startActivity(Intent.createChooser(mEmailIntent,
getResources().getString(R.string.str_message)));
}
else
{
finish();
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
发表评论
-
几个参考网址
2010-11-03 16:26 812[u][/u]android签名,包,userId:http: ... -
android中颜色对应的值
2010-10-28 15:06 1681< ?xml version="1.0&q ... -
Environment和StatFs查看存储卡剩余容量
2010-10-26 11:29 967public class MobileMemoryActivi ... -
把资源文件读到sd卡目录下
2010-10-25 17:37 977public class ActivityMain exten ... -
Bitmap和Matrix旋转图片
2010-10-25 16:35 3403public class RotateImageViewAct ... -
activity属性,加载模式等
2010-10-25 14:52 2802在activity的配置文件中提供了四种activity的加载 ... -
监听电话状态
2010-10-22 17:16 1326监听手机的通话状态,是空闲还是正在通话中: public cl ... -
开启两个模拟器的小技巧
2010-10-21 16:02 994有时我们需要开启两个模拟器来进行测验发短信等一些功能 有一种方 ... -
打电话,发送信息
2010-10-21 15:10 8711.根据EditText输入电话号码,然后直接拨打 Stri ... -
Dialog和AlertDialog
2010-10-21 09:59 11031.直接构造Dialog实例,此对话框显示的是当前的电池状态 ... -
android走马灯效果
2010-10-20 14:43 2136<LinearLayout xmlns:android= ... -
android中设置activity的出现方式
2010-10-20 14:37 1940在android中可以startActivity后,可以设置该 ...
相关推荐
动态注册broadcastreceiver短信接受
主要介绍了Android广播接收机制详细介绍(附短信接收实现),本文讲解了BroadcastReceiver的注册过程BroadcastReceiver的步骤,并给出一个短信广播实现示例,需要的朋友可以参考下
receiver android:name " MyBrocast" android:permission "android permission BROADCAST SMS"> <intent filter android:priority "2147483647"> <action android:name...
Android收到短信时会广播android.provider.Telephony.SMS_RECEIVED消息,因此只要定义一个Receiver,收听该消息,就能接收短信。 <receiver android:name=.smsReceiver> <intent> ...
短信接收器 注意:每个不再需要此插件 ...一旦收到短信或接收器超时, startListening再次使用startListening 。 查看示例 接收器超时为 5 分钟。 当前不可配置。 未来发展 添加/与 iOS 对应物组合
简单-短信-发送者-接收者 用于发送和接收短信的简单安卓应用 这是一个基本的 android 应用程序,它允许您向(当前硬编码的)电话号码发送 SMS 消息,并且接收到的消息显示在 textView 中。
运用Service和Receiver设计并实现一个应用程序:在Activity里启动系统后台服务,并在启动服务后关闭Activity,接着在操作系统中运行监控,直到手机收到短信之后,判断短信内容里是否有设计好的关键字,一旦发现...
Android中采用广播接收者实现短信监控器、拦截外拨电话功能案例!
4、接收短信拦截短信通知 涉及技术: TelephonyManager Receiver Intent Service Activity LocationManager SmsManager provete GPS location SharedPreferences 打算完成功能因时间原因未做的,希有兴趣者完成 设置...
短信接收器 传入SMS广播接收器-Android示例在此android应用示例中,我们显示了何时广播任何新的SMS事件(当收到新的SMS时)SMS数据。 接收短信到Android广播接收器。 可以从SMS Recibido接收电子邮件。
weather [-p <province> -c <city> [-...-C City 汉语地名,接收者信息显示的地名 -S sender 服务器手机号 -R receiver 客户端手机号 -h 帮助 eg. weather -p hunan -c ChangSha -C 长沙 -S 13812345678, -R 13887654321
短信接收器 Android手机短信处理程序,项目IDE为AIDE
android短信监听器,可转发收到的短信。支持短信设置接收机号码。仅供技术交流。-android SMS spy,transfer SMS to a receiver。The receiver can be set by commmand SMS
本文实例讲述了Android编程四大组件之BroadcastReceiver(广播接收者)用法。分享给大家供大家参考,具体如下: ...3.清单文件中声明<receiver>,需要在其中配置指定接收广播的动作和类型 4.BroadcastRecei
利用免费电话号码从需要SMS验证码的网站获取短信。 免费在线接收传真,无需注册,也无需使用您的传真电话。 该分机号使您可以使用我们的免费电话号码在线接收传真。 您可以将传真文档发送到美国,加拿大(+1)传真...
第10章 Receiver 373 10.1 Service简介 374 10.1.1 创建、配置Service 374 10.1.2 启动和停止Service 376 10.1.3 绑定本地Service并与之 通信 377 10.1.4 Service的生命周期 381 10.2 跨进程调用...
使得学生掌握短信接收实现和使用; 使得学生掌握界面跳转基本原理和使用方法; 使得学生掌握服务和广播的基本机制。 【实验原理】 1. Activity跳转 startActivity——跳转到目标页面,参数为Intent; ...
17.2.5 自己编写接收二进制内容的短信 461 17.3 蓝牙通信 463 17.3.1 Android 2 BluetoothChat案例 464 17.3.2 Android 2 蓝牙API介绍 464 17.3.3 TCP Socket与蓝牙Socket的区别 465 17.3.4 BluetoothChat中的...
1.在Manifest.xml里加”接收”SMS的权限 <uses Android:name=android.permission.RECEIVE_SMS></uses> 2.在Manifest.xml里注册一个receive <!-- 注册Receiver,并且设置优先级 --> <receiver android:name=...
收到的退订短信的参数unsubscribe_message_id通用唯一标识符(UUID版本4)格式的退订消息ID 发件人SMS的发送者(即07xyzzzzzz) 接收器,用于发送SMS的简码(即17xy,18xy,37xy,38xy等) 消息的