sqlite データベースに番号が保存されている SMS を傍受したい
私のコード:
public class SMS extends Activity {private static final String DBNAME = "SMS";
private static final String TABLENAME = "LIST";
private static final String FIELD01_NAME = "_id";
private static final String FIELD02_NAME = "_text1";
private SQLiteDatabase db;
private Cursor myCursor;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
db = this.openOrCreateDatabase(DBNAME, MODE_APPEND, null);
String CREATE_SQL = "Create table if not exists " +
TABLENAME + " (" + FIELD01_NAME +
" integer primary key autoincrement, " +
FIELD02_NAME + " varchar not null);";
db.execSQL(CREATE_SQL);
myCursor = db.query(TABLENAME,
null, null, null, null, null, null);}
private BroadcastReceiver mBroadcast = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction()
.equals("android.provider.Telephony.SMS_RECEIVED")) {
this.abortBroadcast();
StringBuffer sb = new StringBuffer();
String sender = null;
String content = null;
String sendtime = null;
Bundle bundle = intent.getExtras();
if (bundle != null) {
Object[] pdus = (Object[]) bundle.get("pdus");
SmsMessage[] mges = new SmsMessage[pdus.length];
for (int i = 0; i < pdus.length; i++) {
mges[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
}
for (SmsMessage mge : mges) {
sb.append("From:" + mge.getDisplayOriginatingAddress()
+ "\n");
sb.append("body:" + mge.getMessageBody());
sender = mge.getDisplayOriginatingAddress();
content = mge.getMessageBody();
Date date = new Date(mge.getTimestampMillis());
SimpleDateFormat format = new SimpleDateFormat(
"yyyy-MM-dd HH:mm:ss");
sendtime = format.format(date);
if (sender.equals( myCursor)) {
abortBroadcast();
}
} Toast.makeText(context, sb.toString(), Toast.LENGTH_LONG)
.show(); }
}
}
};
}
私はそれを実行して動作しません〜私は何が間違っているのかわからないので、誰かが私に正しいコードを教えてくれますか? 私のデータベースはSMS、テーブル名LIST.._text1は数字です..