【问题标题】:With Cordova android app, how I can access (read/write) SQLite file at shared folder in Win10 device?使用 Cordova android 应用程序,我如何在 Win10 设备的共享文件夹中访问(读/写)SQLite 文件?
【发布时间】:2022-01-01 00:10:31
【问题描述】:

我在 WINDOWS 设备中有共享文件夹,我可以从任何其他 Windows 设备访问该文件夹,但我需要通过 Cordova 开发的 android 应用程序访问该文件夹并(读/写)其内容,特别是 sqlite 文件。 有没有什么插件可以帮忙?? 我试过了 科尔多瓦插件文件 和 科尔多瓦-sqlite-evcore-extbuild-free 但还是找不到任何帮助

这是我在 Android 文件夹中读/写内部数据库 SQlite 的代码

document.addEventListener('deviceready', function() {

var dirr = 'file:///storage/emulated/0/Android';

//var dirr = '//192.168.1.29/shrd'; // That What I need

window.resolveLocalFileSystemURL(dirr, function(externalDataDirectoryEntry) {

var db = window.sqlitePlugin.openDatabase({name: 'shared.db', androidDatabaseLocation: externalDataDirectoryEntry.toURL()});

  db.transaction(function(tx) {
    tx.executeSql('CREATE TABLE IF NOT EXISTS MyTable (data)');
    tx.executeSql('INSERT INTO MyTable VALUES (?)', ['test-value']);
  }, function(error) {
    console.log('Populate database error: ' + error.message);

  }, function() {
    db.transaction(function(tx) {
    
      tx.executeSql('SELECT data from MyTable', [], function(tx_ignored, resultSet) {
      
        console.log('Record count: ' + resultSet.rows.length);
         for (var i=0; i < resultSet.rows.length; ++i)
         console.log('index: ' + i + ' value: ' + resultSet.rows.item(i).data);
          });
    }, function(error) {
      console.log('Populate database error: ' + error.message);
    });
  });
});

有什么帮助吗?

【问题讨论】:

    标签: android sqlite cordova shared-directory


    【解决方案1】:

    如果您的应用仅适用于Android,那么您可以尝试cordova-plugin-samba 并使用samba 通过smb://192.168.1.29/shrd 连接网络

    【讨论】:

    • 感谢您的评论,我的应用程序只有 android,但我尝试了这个 cordova-plugin-samba 但我不知道如何使用它..你能帮帮我吗?
    • 这个问题太宽泛,无法在这里回答。您应该谷歌如何在 Windows 中打开 samba 共享以及如何连接到 samba 共享。这超出了本主题的范围。你应该验证这个答案,然后如果你遇到一些连接到 samba 共享的问题,然后再创建一个问题,因为这不再是关于 Cordova...
    猜你喜欢
    • 2017-11-22
    • 2018-12-18
    • 1970-01-01
    • 2015-01-19
    • 2012-03-12
    • 2019-08-18
    • 1970-01-01
    • 1970-01-01
    • 2020-03-26
    相关资源
    最近更新 更多