先上代码: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版本求救各位大虾帮忙