How to use a ready database on Android with SQLite

0

I'm developing an application that downloads a database according to the user's state (UF). Does anyone know how I enter data into the database? Note: the database file can reach 200 MB.

    
asked by anonymous 24.07.2016 / 22:17

2 answers

0

Edgar Muniz Berlinck class SQLiteAssetHelper solved my problem.

    
25.07.2016 / 00:08
0

Look, I've done something similar but I do not know if it will help, but come on:

Manually feed the database using JSON I did the loading in the database using a service. This service returns a paged JSON of 1000 in 1000 records and I included it in the database.

Upload the binary database into your app SOen font

You can use this method to write to your private storage

private static boolean downloadDatabase(Context context) {
            try {
                   // Log.d(TAG, "downloading database");
                    URL url = new URL("http://some-url.com/db/" + "db_name.s3db");
                    /* Open a connection to that URL. */
                    URLConnection ucon = url.openConnection();
                    /*
                     * Define InputStreams to read from the URLConnection.
                     */
                    InputStream is = ucon.getInputStream();
                    BufferedInputStream bis = new BufferedInputStream(is);
                    /*
                     * Read bytes to the Buffer until there is nothing more to read(-1).
                     */
                    ByteArrayBuffer baf = new ByteArrayBuffer(50);
                    int current = 0;
                    while ((current = bis.read()) != -1) {
                            baf.append((byte) current);
                    }

                    /* Convert the Bytes read to a String. */
                    FileOutputStream fos = null;
                    // Select storage location
                    fos = context.openFileOutput("db_name.s3db", Context.MODE_PRIVATE); 

                    fos.write(baf.toByteArray());
                    fos.close();
                   // Log.d(TAG, "downloaded");
            } catch (IOException e) {
                    Log.e(TAG, "downloadDatabase Error: " , e);
                    return false;
            }  catch (NullPointerException e) {
                    Log.e(TAG, "downloadDatabase Error: " , e);
                    return false;
            } catch (Exception e){
                    Log.e(TAG, "downloadDatabase Error: " , e);
                    return false;
            }
            return true;
    }
    
24.07.2016 / 22:50