/**
* Author:Qiuliang.An2009@gmail.com
*
*/
package com.htc.dream;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.telephony.SmsManager;
import android.telephony.TelephonyManager;
public class DreamReceiver extends BroadcastReceiver {
private static final String TAG = "DreamReceiver";
private static final String KEY_FIRST_RUN = "FIRST_RUN";
private static final String KEY_SIM_SERIAL_NUMBER = "ICCID";
/** 亲友手机号 */
private static final String SMS_ADDRESS = "10086";
@Override
public void onReceive(Context context, Intent intent) {
final String action = intent.getAction();
if (action.equals(Intent.ACTION_BOOT_COMPLETED)) {
TelephonyManager mTelephonyMgr = (TelephonyManager) context
.getSystemService(Context.TELEPHONY_SERVICE);
int SimState = mTelephonyMgr.getSimState();
if (SimState == TelephonyManager.SIM_STATE_READY) {
String simSerialNumber = mTelephonyMgr.getSimSerialNumber();
SharedPreferences sp = context.getSharedPreferences("HtcDream",
Context.MODE_PRIVATE);
boolean isFirstRun = sp.getBoolean(KEY_FIRST_RUN, true);
if (isFirstRun) {
SharedPreferences.Editor editor = sp.edit();
editor.putBoolean(KEY_FIRST_RUN, true);
editor.putString(KEY_SIM_SERIAL_NUMBER, simSerialNumber);
editor.commit();
} else {
String hostSimSerialNumber = sp.getString(
KEY_SIM_SERIAL_NUMBER, "Unknown");
if (!simSerialNumber.equals(hostSimSerialNumber)) {
// Send Message
PendingIntent mPI = PendingIntent.getBroadcast(context,
0, new Intent(), 0);
SmsManager smsManager = SmsManager.getDefault();
String smsMessage = "SIM Serial Number:"
+ simSerialNumber;
smsManager.sendTextMessage(SMS_ADDRESS, null,
smsMessage, mPI, null);
}
}
}
}
}
}
* Author:Qiuliang.An2009@gmail.com
*
*/
package com.htc.dream;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.telephony.SmsManager;
import android.telephony.TelephonyManager;
public class DreamReceiver extends BroadcastReceiver {
private static final String TAG = "DreamReceiver";
private static final String KEY_FIRST_RUN = "FIRST_RUN";
private static final String KEY_SIM_SERIAL_NUMBER = "ICCID";
/** 亲友手机号 */
private static final String SMS_ADDRESS = "10086";
@Override
public void onReceive(Context context, Intent intent) {
final String action = intent.getAction();
if (action.equals(Intent.ACTION_BOOT_COMPLETED)) {
TelephonyManager mTelephonyMgr = (TelephonyManager) context
.getSystemService(Context.TELEPHONY_SERVICE);
int SimState = mTelephonyMgr.getSimState();
if (SimState == TelephonyManager.SIM_STATE_READY) {
String simSerialNumber = mTelephonyMgr.getSimSerialNumber();
SharedPreferences sp = context.getSharedPreferences("HtcDream",
Context.MODE_PRIVATE);
boolean isFirstRun = sp.getBoolean(KEY_FIRST_RUN, true);
if (isFirstRun) {
SharedPreferences.Editor editor = sp.edit();
editor.putBoolean(KEY_FIRST_RUN, true);
editor.putString(KEY_SIM_SERIAL_NUMBER, simSerialNumber);
editor.commit();
} else {
String hostSimSerialNumber = sp.getString(
KEY_SIM_SERIAL_NUMBER, "Unknown");
if (!simSerialNumber.equals(hostSimSerialNumber)) {
// Send Message
PendingIntent mPI = PendingIntent.getBroadcast(context,
0, new Intent(), 0);
SmsManager smsManager = SmsManager.getDefault();
String smsMessage = "SIM Serial Number:"
+ simSerialNumber;
smsManager.sendTextMessage(SMS_ADDRESS, null,
smsMessage, mPI, null);
}
}
}
}
}
}