将来自特定号码的传入SMS存储到sqlite DB

时间:2015-06-11 08:44:30

标签: android sqlite broadcastreceiver

我正在使用BroadcastReceiver收听收到的消息并在WebView中显示消息,如果是来自特定的消息,我已实现此部分...现在我该如何存储此消息从特定发件人发送到SQLite Database点击事件Button ...提前感谢

1 个答案:

答案 0 :(得分:0)

好吧,就像你将数据保存在数据库中一样。读这个: http://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html

您还可以使用ORM使一切变得更轻松,这样您就不必自己使用数据库了。 Sugar ORM是Android开发人员的一个很好的选择: http://satyan.github.io/sugar/

编辑:

为了创建自己的数据库并自己处理表的创建,你必须创建一个扩展SQLiteOpenHelper的类,我没有那么多。但是你可以在这里看到示例代码:

http://paste.ubuntu.com/11695543/

如果你想使用Sugar ORM,你必须将它的库添加到你的项目中,你想要保存在数据库中的数据类现在应该扩展SugarRecord。一切都在文档中。例如:

public class Box extends SugarRecord<Box> {

public int picID;
public int lockedPicId;
public int isBought;
public int id;
public int numberOfLevels;
public String packageName;


public int getNumberOfPassed(){
    ArrayList<Level> levels = (ArrayList<Level>) Level.find(Level.class, "level_Box = ?", this.getId() + "");
    int res = 0;
    for(int i = 0; i < levels.size(); i++){
        if(levels.get(i).isFinished == 1)
            res++;
    }
    return res;
}
public Box(int id, int numberOfLevels, String packageName, int isBought, int picID, int lockedPicId) {
    this.id = id;
    this.numberOfLevels = numberOfLevels;
    this.packageName = packageName;
    this.isBought = isBought;
    this.picID = picID;
    this.lockedPicId = lockedPicId;
}

public Box() {

}

}

所以从现在开始,如果你想保存一个你刚写的对象:

Box box = new Box();
//do anything you want here.
box.save();

就是这样。要检索它们,您可以阅读文档。