Note that there are some explanatory texts on larger screens.

plurals
  1. POIntercept SMS with SQLite
    primarykey
    data
    text
    <p>I want to Intercept SMS that number is saved in a sqlite database</p> <p>my code:</p> <pre><code>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 &lt; 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(); } } } }; } </code></pre> <hr> <p>I run it and it does not work~ I don't know what I am doing wrong and can anyone give me the right code? my db is SMS, table name LIST.. _text1 are the numbers..</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload