sqlite - 从原生访问flutter sqflite插件的sqlite数据库
问题描述
我正在开发一个颤振应用程序,它有几个原生部分,
在颤振中使用 sqflite 插件创建数据库文件。
initDB() async{
String databasPath = await getDatabasesPath();
String path = join(databasPath,'eshaar.db');
var Db = await openDatabase(path,version: 4,onCreate: _onCreate);
return Db;
}
我想访问此类中的数据库,用于在应用程序终止时收到通知时在特定表中添加记录。
import androidx.core.app.NotificationCompat;
import com.onesignal.NotificationExtenderService;
import com.onesignal.OSNotificationDisplayedResult;
import com.onesignal.OSNotificationReceivedResult;
import java.math.BigInteger;
public class MyNotificationService extends NotificationExtenderService {
@Override
protected boolean onNotificationProcessing(OSNotificationReceivedResult receivedResult) {
OverrideSettings overrideSettings = new OverrideSettings();
overrideSettings.extender = new NotificationCompat.Extender() {
@Override
public NotificationCompat.Builder extend(NotificationCompat.Builder builder) {
if (!receivedResult.restoring) {
// Only set custom channel if notification is not being restored
// Note: this would override any channels set through the OneSignal dashboard
return builder.setChannelId("News");
}
return builder.setChannelId("News");
}
};
/* Do something with notification payload */
try{
String title = receivedResult.payload.title;
String body = receivedResult.payload.body;
String sender_id = receivedResult.payload.additionalData.getString("sender_id");
Log.d("body: ",body.toString());
// Writes additionalData values to local database
// SQLiteDatabase db = dbHelper.getWritableDatabase();
// ContentValues values = new ContentValues();
// values.put(FeedEntry.COLUMN_NAME_ARTICLE_TITLE, additionalData.articleTitle);
// values.put(FeedEntry.COLUMN_NAME_ARTICLE_ID, additionalData.articleId);
// long newRowId = db.insert(FeedEntry.TABLE_NAME, null, values);
}catch (Exception e){
Log.d("Notification: ",e.toString());
}
return false;
}
} ```
解决方案
推荐阅读
- jenkins - 我们如何向用户或团队提供对特定 Jenkins 作业的访问权限?
- node.js - 为什么我的节点模块没有在 react-native 中使用?
- c++ - 如何子类化组合框编译错误
- mainframe - JCL 在一行中合并记录
- java - 如何在java中将字符串时间戳转换为日期?
- terraform - 在 Terraform Enterprise 中可以创建的工作空间的数量是否有限制?
- python - ValueError:'X'不在列表中,为什么我不能使用字符串查找和替换
- jira-xray - 在文档生成器中添加前提条件描述
- javascript - Selectpicker 选择了第一个选项,但 selectpicker 标题是“未选择”
- android - 如何在 Flutter 中设计定时器