先上代码:BroadcastReceiver:public class SmsReceive extends BroadcastReceiver { @SuppressLint({ "SimpleDateFormat", "HandlerLeak" })
@Override
public void onReceive(Context context, Intent intent) {
SmsMessage msg = null;
Bundle bundle = intent.getExtras();
if (bundle != null) {
Object[] pdusObj = (Object[]) bundle.get("pdus");
for (Object p : pdusObj) {
msg = SmsMessage.createFromPdu((byte[]) p);
//开启一个服务,服务负责Email的发送
Bundle bundle2 = new Bundle();
bundle2.putString("msg", "有新的短信"); Intent serviceIntent = new Intent(context,
MailSenderSerivce.class);
serviceIntent.putExtras(bundle2);
context.startService(serviceIntent); }
return;
} }}MailSenderSerivce:
public class MailSenderSerivce extends Service { @Override
public IBinder onBind(Intent intent) {
System.out.println("服务 onBind 被调用!");
return null;
} @Override
public void onCreate() {
System.out.println("服务 onCreate 被调用!");
super.onCreate();
} @SuppressLint("SimpleDateFormat")
@SuppressWarnings("deprecation")
@Override
public void onStart(Intent intent, int startId) {
Bundle bundle = intent.getExtras();
final String msg = bundle.getString("msg");
new Thread() {
@SuppressLint("ShowToast")
@Override
public void run() {
try {
MailEntity mailInfo = new MailEntity();
mailInfo.setMailServerHost("smtp.qq.com");
mailInfo.setMailServerPort("25");
mailInfo.setValidate(true);
mailInfo.setUserName("admin"); // 你的邮箱地址
mailInfo.setPassword("123456");// 您的邮箱密码
mailInfo.setFromAddress("[email protected]");
mailInfo.setToAddress("[email protected]");
mailInfo.setSubject("from my android");
mailInfo.setContent(msg);
MailSender send = new MailSender();
send.sendTextMail(mailInfo);
} catch (Exception e) {
}
}
}.start();
System.out.println("服务 onstart 被调用!");
super.onStart(intent, startId);
} @Override
public int onStartCommand(Intent intent, int flags, int startId) { System.out.println("服务 onStartCommand 被调用!");
return super.onStartCommand(intent, flags, startId);
}}
这段代码在Eclipse中运行正常,邮件也可以正常的收到但是一旦安装到手机里就不行了,没有任何反应,也不报错
我的手机是小米2S,安卓版本是 4.1.1,模拟器中的安卓是4.0.3版本求救各位大虾帮忙
@Override
public void onReceive(Context context, Intent intent) {
SmsMessage msg = null;
Bundle bundle = intent.getExtras();
if (bundle != null) {
Object[] pdusObj = (Object[]) bundle.get("pdus");
for (Object p : pdusObj) {
msg = SmsMessage.createFromPdu((byte[]) p);
//开启一个服务,服务负责Email的发送
Bundle bundle2 = new Bundle();
bundle2.putString("msg", "有新的短信"); Intent serviceIntent = new Intent(context,
MailSenderSerivce.class);
serviceIntent.putExtras(bundle2);
context.startService(serviceIntent); }
return;
} }}MailSenderSerivce:
public class MailSenderSerivce extends Service { @Override
public IBinder onBind(Intent intent) {
System.out.println("服务 onBind 被调用!");
return null;
} @Override
public void onCreate() {
System.out.println("服务 onCreate 被调用!");
super.onCreate();
} @SuppressLint("SimpleDateFormat")
@SuppressWarnings("deprecation")
@Override
public void onStart(Intent intent, int startId) {
Bundle bundle = intent.getExtras();
final String msg = bundle.getString("msg");
new Thread() {
@SuppressLint("ShowToast")
@Override
public void run() {
try {
MailEntity mailInfo = new MailEntity();
mailInfo.setMailServerHost("smtp.qq.com");
mailInfo.setMailServerPort("25");
mailInfo.setValidate(true);
mailInfo.setUserName("admin"); // 你的邮箱地址
mailInfo.setPassword("123456");// 您的邮箱密码
mailInfo.setFromAddress("[email protected]");
mailInfo.setToAddress("[email protected]");
mailInfo.setSubject("from my android");
mailInfo.setContent(msg);
MailSender send = new MailSender();
send.sendTextMail(mailInfo);
} catch (Exception e) {
}
}
}.start();
System.out.println("服务 onstart 被调用!");
super.onStart(intent, startId);
} @Override
public int onStartCommand(Intent intent, int flags, int startId) { System.out.println("服务 onStartCommand 被调用!");
return super.onStartCommand(intent, flags, startId);
}}
这段代码在Eclipse中运行正常,邮件也可以正常的收到但是一旦安装到手机里就不行了,没有任何反应,也不报错
我的手机是小米2S,安卓版本是 4.1.1,模拟器中的安卓是4.0.3版本求救各位大虾帮忙
解决方案 »
- TextView滚动问题
- 请教,googlemapview中如何隐藏一个继承自ItemizedOverlay<OverlayItem>的自定义overlay?
- struts2 框架异常
- Android SAX解析 怎么得到单独属性
- 请教关于这个效果怎么实现的?
- 使用adb shell命令后,想列出data目录下的文件却说没权限,这是为什么?
- opencv移植到andriod平台出现了问题
- 关于操作其他目录下数据库权限问题?
- 修改android原生音乐播放器的问题!!!!
- Android程序添加一个服务,如果程序遇到异常退出,则服务重启程序
- andriod链接sql server 数据库
- 文件浏览如何进行分页listview显示
可能手机网络的问题。