在 aBroadcastReceiver
中,我收到拨出电话的号码。
我想将此电话号码与我存储在 SQL 数据库中的号码进行比较。
可悲的是,我无法访问BroadcastReceiver
我的数据库。在其他活动中它工作正常。
这是代码BroadcastReceiver
:
public void onReceive(Context context, Intent intent) {
Bundle bundle = intent.getExtras();
//[ getting "string phonenumber" (works)]
mySQLiteAdapter = new SQLiteAdapter(context);
mySQLiteAdapter.openToRead();
sqLiteDatabase = sqLiteHelper.getReadableDatabase();
Cursor cursor = sqLiteDatabase.rawQuery("SELECT * FROM MYDATABASE_TABLE =" + potatos, null);
if(cursor.getCount() > 0) {
cursor.moveToFirst();
while(!cursor.isAfterLast()) {
cursor.moveToNext();
}
}
}
}
代码在SQLiteAdapter
public SQLiteAdapter openToRead() throws android.database.SQLException {
sqLiteHelper = new SQLiteHelper(context, MYDATABASE_NAME, null, MYDATABASE_VERSION);
sqLiteDatabase = sqLiteHelper.getReadableDatabase();
return this;
}