我有一个代码,应该在收到短信时导入数据库。
我的问题是我不知道如何在广播接收器类中调用数据库方法
我想打电话给这样的话:
SELECT * FROM company WHERE sn=1
我得到它像评论!我知道这对于一些人来说是愚蠢和简单的但我刚接触java,我正在使用android studio 2.0
DatabaseHelper.java:
WHERE
IncomingSMSReceiver.java
TouliosDB.eisagoghfititi(temaxismeno_sms[1],temaxismeno_sms[2],temaxismeno_sms[3],temaxismeno_sms[4]);
sms_server.java
package toulios.ptixiakh.toulios;
import android.content.ContentValues;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
public class DatabaseHelper extends SQLiteOpenHelper {
public static final String DATABASE_NAME="Toulios.db";
public static final String TABLE_NAME="Foitites_table";
public static final String Col_AM="AM";
public static final String Col_ONOMA="ONOMA";
public static final String Col_EPITHETO="EPITHETO";
public static final String Col_EXAMINO="EXAMINO";
public DatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, 1);
// SQLiteDatabase db=this.getWritableDatabase();
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("create table " + TABLE_NAME+"(AM INTEGER PRIMARY KEY,ONOMA TEXT,EPITHETO TEXT, EXAMINO INTEGER)");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS"+TABLE_NAME);
onCreate(db);
}
public boolean eisagoghfititi(String am,String onoma,String epitheto,String examino)
{
SQLiteDatabase db=this.getWritableDatabase();
ContentValues contentValues = new ContentValues();
contentValues.put(Col_AM,am);
contentValues.put(Col_ONOMA,onoma);
contentValues.put(Col_EPITHETO,epitheto);
contentValues.put(Col_EXAMINO,examino);
long result = db.insert(TABLE_NAME,null,contentValues);
if(result == -1)
return false;
else
return true;
}
}
答案 0 :(得分:0)
我真的不明白你的问题。只需从您的DatabaseHelper类中调用您的方法即可。替换TouliosDB.eisagoghfititi(temaxismeno_sms[1],temaxismeno_sms[2],temaxismeno_sms[3],temaxismeno_sms[4]);
带
DatabseHelper dbHelper = new DatabaseHelper(context.getApplicationContext());
dbHelper.eisagoghfititi(temaxismeno_sms[1],temaxismeno_sms[2],temaxismeno_sms[3],temaxismeno_sms[4]);