folks. I'm making a broadcast receiver to "black list" contacts on android. So I have two forms to add contacts to the blacklist. One of them is adding them manually to a sqlite database, and the other is adding them from the contacts app. When I receive a sms text from a number from the blacklist, my app should catch the event and send a message in response. I got problems when I'm trying to verify the number on the blacklist. I'm fetching the number and using a cursor with a select to verify the existence of the contact. When the cursor check the number added manually I got no problems but when the contact is added from the contact app the cursor returns 0 rows. Note that I talk Spanish so some words are in spanish.
public class RecibirMensaje extends BroadcastReceiver{
static final String ACTION="android.provider.Telephony.SMS_RECEIVED";
SmsMessage message;
String dbName="DBRespuestas";
String tableRegistro="registro";
SQLiteDatabase db;
EditText nombre,telefono,mensaje;
Context context;
@Override
public void onReceive(Context context, Intent intent){
db=context.openOrCreateDatabase(dbName,Context.MODE_PRIVATE,null);
this.context=context;
if (intent.getAction().equals(RecibirMensaje.ACTION)){
StringBuilder stringBuilder=new StringBuilder();
String textMessage;
Bundle bundle=intent.getExtras();
if (bundle!=null){
Object[]pdus=(Object[])bundle.get("pdus");
for (Object pdu:pdus){
message= SmsMessage.createFromPdu((byte[]) pdu);
}
}
Toast.makeText(context,message.getDisplayOriginatingAddress().toString(),Toast.LENGTH_LONG).show();
if (isBlacklisted(message.getDisplayOriginatingAddress())){
}
}
}
private boolean isBlacklisted(String phone) {
db=context.openOrCreateDatabase(dbName,Context.MODE_PRIVATE,null);
Cursor cursor=db.rawQuery("Select nombre, telefono from registro where telefono='"+phone+"'",null);
cursor.moveToFirst();
if (cursor.getCount()>=0){
Toast.makeText(context,Integer.toString(cursor.getCount()),Toast.LENGTH_LONG).show();
return true;
}else {
Toast.makeText(context,"Cursor vacio",Toast.LENGTH_LONG).show();
return false;
}
}
}
I checked if the passing data is correct with no luck, check the data in the database too. Any help is apreciated. Thanks in advance.