喂..
我正在制作一个应用程序,我在其中检测 SIM 是否已更改..?在安装我的应用程序时,我将当前 SIM 序列号存储在共享首选项中。在启动时,我已经注册了一个广播接收器。在onReceive()
方法中,我正在访问当前的 SIM 序列号并将其与安装时存储的序列号进行比较,以下是我的接收器代码:
package com.secuirity.sms;
import org.apache.harmony.xnet.provider.jsse.GMailSender;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.telephony.SmsManager;
import android.telephony.TelephonyManager;
import android.util.Log;
public class BootUpReciever extends BroadcastReceiver{
Context context;
String email;
String currentSimSerial;
SharedPreferences settings;
SmsManager smsMgr = SmsManager.getDefault();
public static final String PREFS_NAME = "MyPrefsFile";
@Override
public void onReceive(Context context, Intent intent) {
settings = context.getSharedPreferences(PREFS_NAME, 0);
String storedSimSerial = settings.getString("storedSimSerial", null);
Log.d("Stored Sim Serial::",storedSimSerial);
TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
currentSimSerial = tm.getSimSerialNumber();
Log.d("Current Sim Serial","::"+currentSimSerial);
String trustedNum = settings.getString("cellno", null);
email = settings.getString("email", null);
if(currentSimSerial == storedSimSerial){
}else{
Log.d("Sim changed","!!!");
new GmailAsync().execute("");
String sms = "Sim card has changed, " +
"Sim Serial Number of this card is\n"+currentSimSerial+
"Network Operator"+tm.getNetworkOperatorName();
smsMgr.sendTextMessage(trustedNum, null,sms, null, null);
}
Intent sms = new Intent(context, SMSReceiver.class);
sms.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(sms);
Intent netAvailability = new Intent(context, CheckingNetworkAvailability.class);
netAvailability.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(netAvailability);
}
public class GmailAsync extends AsyncTask<String, Void, String>{
@Override
protected String doInBackground(String... params) {
// TODO Auto-generated method stub
String mail_body = "Sim serial number is "+currentSimSerial;
String subject = "Your Sim has changed!!!";
GMailSender sender = new GMailSender("securemob.viasms@gmail.com", "smsfun890");
try {
sender.sendMail(subject,
mail_body+"\nThanks for using Mobile Security App",
"securemob.viasms@gmail.com",
email,null);
} catch (Exception e) {
Log.e("SendMail", e.getMessage(), e);
}
return null;
}
@Override
protected void onPostExecute(String result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
Log.d("Mail","Sent");
}
}
}
但它不工作.... :(:(:( 我有以下权限 READ_PHONE_STATE" 和 "RECEIVE_BOOT_COMPLETED"