vendredi 26 février 2016

What is the best way to send whole .db file from android wear to smartphone?

Now I am making an wear app that records accelerator, magnet-field, gyroscope (50Hz) and write them to a .db file (that contains 3 tables(acceleration, magnet-field, gyroscope) using SQLiteOpenHelper.

Once a day, I would like to send the .db file to its handheld.

I think it is the best to use DataApi and I tried to replace Realm by SQLite in this code(http://ift.tt/1QkuiFs).

In this code, I thought this part

public static void syncRealm(Context context){
        File writableFolder = context.getFilesDir();
        File realmFile = new File(writableFolder, Realm.DEFAULT_REALM_NAME);
        Asset realAsset = Tools.assetFromFile(realmFile);
        new FileSender(realAsset, context).execute();
}

should be changed like this

 public static void syncDB(Context context) {
    WearSqliteOpenHelper helper = new WearSqliteOpenHelper(context);
    String dbPath = helper.getReadableDatabase().getPath();
    File dbFile = new File(dbPath);
    Uri dbUri = Uri.fromFile(dbFile);
    Asset realAsset = Asset.createFromUri(dbUri);
    new FileSender(realAsset, context).execute();
  }

but I don't know how to convert (byte [] byteArray) to .db file in handheld. (What is the alternative function of "toFile" below. this code is also in http://ift.tt/1QkuiFs)

   private void toFile(byte [] byteArray){
        File writableFolder = ListenerService.this.getFilesDir();
        File realmFile = new File(writableFolder, Realm.DEFAULT_REALM_NAME);
        if (realmFile.exists()) {
            realmFile.delete();
        }
        try {
            FileOutputStream fos=new FileOutputStream(realmFile.getPath());
            fos.write(byteArray);
            fos.close();
        }
        catch (java.io.IOException e) {
            Log.d(TAG, "toFile exception: " + e.getLocalizedMessage());
        }
    }

Please help me!!!

Aucun commentaire:

Enregistrer un commentaire