samedi 28 novembre 2015

Getting database values in if statement

I have a database which contains multiple phone numbers. I need to check if the database contains a specific number. How do I get the database values in an if statement? Should i use Array List?

This is what i have been doing so far..

@Override
public void onReceive(Context context, Intent intent) {
Bundle bund=intent.getExtras();
String space="";

if(bund!=null) {  
Object[] smsExtra = (Object[]) bund.get(SMS_EXTRA_NAME);

for (int i = 0; i < smsExtra.length; i++) {
SmsMessage sms = SmsMessage.createFromPdu((byte[]) smsExtra[i]);
body = sms.getMessageBody().toString();
address = sms.getOriginatingAddress();

db = openOrCreateDatabase("Admindb", MODE_PRIVATE, null);
Cursor crs = db.rawQuery("select * from adminstbl", null);
String[] str= new String[crs.getCount()];
crs.moveToFirst();
for(int k=0;k<str.length;k++)
{
str[k] = crs.getString(crs.getColumnIndex("Number"));
crs.moveToNext();
}

if (address.equals(str)){
 //do my task here
}

Aucun commentaire:

Enregistrer un commentaire