├── .github └── FUNDING.yml ├── .gitignore ├── .idea ├── .name ├── compiler.xml ├── copyright │ └── profiles_settings.xml ├── encodings.xml ├── gradle.xml ├── misc.xml ├── modules.xml └── runConfigurations.xml ├── License ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── assets │ ├── external_db_android.db3 │ └── external_db_android.sqlite │ ├── java │ └── com │ │ └── ajts │ │ └── androidmads │ │ └── sqliteimpexsample │ │ ├── DbQueries.java │ │ └── MainActivity.java │ └── res │ ├── layout │ ├── activity_main.xml │ └── list_item.xml │ ├── mipmap-hdpi │ └── ic_launcher.png │ ├── mipmap-mdpi │ └── ic_launcher.png │ ├── mipmap-xhdpi │ └── ic_launcher.png │ ├── mipmap-xxhdpi │ └── ic_launcher.png │ ├── mipmap-xxxhdpi │ └── ic_launcher.png │ ├── values-w820dp │ └── dimens.xml │ └── values │ ├── colors.xml │ ├── dimens.xml │ ├── strings.xml │ └── styles.xml ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── library ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── ajts │ │ └── androidmads │ │ └── sqliteimpex │ │ └── SQLiteImporterExporter.java │ └── res │ └── values │ └── strings.xml └── settings.gradle /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: androidmads 4 | patreon: # Replace with a single Patreon username 5 | open_collective: # Replace with a single Open Collective username 6 | ko_fi: https://ko-fi.com/mushtaq 7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 9 | liberapay: # Replace with a single Liberapay username 10 | issuehunt: # Replace with a single IssueHunt username 11 | otechie: # Replace with a single Otechie username 12 | custom: # Replace with a single custom sponsorship URL 13 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | -------------------------------------------------------------------------------- /.idea/.name: -------------------------------------------------------------------------------- 1 | SQLiteImporterExporter -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 18 | 19 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 19 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 46 | 47 | 48 | 49 | 50 | 1.8 51 | 52 | 57 | 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /License: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 AndroidMad / Mushtaq M A 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SQLiteImporterExporter 2 | A light weight library for exporting and importing sqlite database in android 3 | ## Created By 4 | [![API](https://img.shields.io/badge/AndroidMads-AJTS-brightgreen.svg?style=flat)](https://github.com/androidmads/SQLiteImporterExporter) 5 | ## How to Download 6 | Gradle: 7 | ```groovy 8 | compile 'com.ajts.androidmads.sqliteimpex:library:1.0.0' 9 | ``` 10 | Maven: 11 | ```groovy 12 | 13 | com.ajts.androidmads.sqliteimpex 14 | library 15 | 1.0.0 16 | pom 17 | 18 | ``` 19 | ## How to use this Library: 20 | This Library is used to import SQLite Database from Assets or External path and Export/Backup SQLite Database to external path. 21 | 22 | ```java 23 | SQLiteImporterExporter sqLiteImporterExporter = new SQLiteImporterExporter(getApplicationContext(), db); 24 | 25 | // Listeners for Import and Export DB 26 | sqLiteImporterExporter.setOnImportListener(new SQLiteImporterExporter.ImportListener() { 27 | @Override 28 | public void onSuccess(String message) { 29 | Toast.makeText(getApplicationContext(), message, Toast.LENGTH_SHORT).show(); 30 | } 31 | 32 | @Override 33 | public void onFailure(Exception exception) { 34 | Toast.makeText(getApplicationContext(), exception.getMessage(), Toast.LENGTH_SHORT).show(); 35 | } 36 | }); 37 | 38 | sqLiteImporterExporter.setOnExportListener(new SQLiteImporterExporter.ExportListener() { 39 | @Override 40 | public void onSuccess(String message) { 41 | Toast.makeText(getApplicationContext(), message, Toast.LENGTH_SHORT).show(); 42 | } 43 | 44 | @Override 45 | public void onFailure(Exception exception) { 46 | Toast.makeText(getApplicationContext(), exception.getMessage(), Toast.LENGTH_SHORT).show(); 47 | } 48 | }); 49 | ``` 50 | 51 | #### To Import SQLite from Assets 52 | ```java 53 | try { 54 | sqLiteImporterExporter.importDataBaseFromAssets(); 55 | } catch (Exception e) { 56 | e.printStackTrace(); 57 | } 58 | ``` 59 | 60 | #### To import from external storage 61 | ```java 62 | try { 63 | sqLiteImporterExporter.importDataBase(path); 64 | } catch (Exception e) { 65 | e.printStackTrace(); 66 | } 67 | ``` 68 | 69 | #### To export to external storage 70 | ```java 71 | try { 72 | sqLiteImporterExporter.exportDataBase(path); 73 | } catch (Exception e) { 74 | e.printStackTrace(); 75 | } 76 | ``` 77 | #### License 78 | ``` 79 | MIT License 80 | 81 | Copyright (c) 2017 AndroidMad / Mushtaq M A 82 | 83 | Permission is hereby granted, free of charge, to any person obtaining a copy 84 | of this software and associated documentation files (the "Software"), to deal 85 | in the Software without restriction, including without limitation the rights 86 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 87 | copies of the Software, and to permit persons to whom the Software is 88 | furnished to do so, subject to the following conditions: 89 | 90 | The above copyright notice and this permission notice shall be included in all 91 | copies or substantial portions of the Software. 92 | 93 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 94 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 95 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 96 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 97 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 98 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 99 | SOFTWARE. 100 | ``` 101 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 25 5 | buildToolsVersion '25.0.2' 6 | 7 | defaultConfig { 8 | applicationId "com.ajts.androidmads.sqliteimpexsample" 9 | minSdkVersion 15 10 | targetSdkVersion 25 11 | versionCode 1 12 | versionName "1.0" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | 21 | lintOptions{ 22 | abortOnError false 23 | } 24 | } 25 | 26 | dependencies { 27 | compile fileTree(include: ['*.jar'], dir: 'libs') 28 | compile 'com.android.support:appcompat-v7:25.2.0' 29 | compile project(path: ':library') 30 | } 31 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in F:\AndroidWorks\SoftWare\AndroidStudio\sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /app/src/main/assets/external_db_android.db3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/androidmads/SQLiteImporterExporter/cdf6e039ca36cfe1b4ba687fbdff28e5482a83fc/app/src/main/assets/external_db_android.db3 -------------------------------------------------------------------------------- /app/src/main/assets/external_db_android.sqlite: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/androidmads/SQLiteImporterExporter/cdf6e039ca36cfe1b4ba687fbdff28e5482a83fc/app/src/main/assets/external_db_android.sqlite -------------------------------------------------------------------------------- /app/src/main/java/com/ajts/androidmads/sqliteimpexsample/DbQueries.java: -------------------------------------------------------------------------------- 1 | package com.ajts.androidmads.sqliteimpexsample; 2 | 3 | import android.content.ContentValues; 4 | import android.content.Context; 5 | import android.database.Cursor; 6 | import android.database.SQLException; 7 | import android.database.sqlite.SQLiteDatabase; 8 | import android.util.Log; 9 | 10 | import com.ajts.androidmads.sqliteimpex.SQLiteImporterExporter; 11 | 12 | import java.util.ArrayList; 13 | 14 | class DbQueries { 15 | private Context context; 16 | private SQLiteDatabase database; 17 | private SQLiteImporterExporter dbHelper; 18 | 19 | DbQueries(Context context) { 20 | this.context = context; 21 | } 22 | 23 | public DbQueries open() throws SQLException { 24 | dbHelper = new SQLiteImporterExporter(context, MainActivity.db); 25 | database = dbHelper.getWritableDatabase(); 26 | return this; 27 | } 28 | 29 | void close() { 30 | dbHelper.close(); 31 | } 32 | 33 | long insertDetail(String stud_name) { 34 | ContentValues values = new ContentValues(); 35 | values.put("student_name", stud_name); 36 | return database.insert("student_details", null, values); 37 | } 38 | 39 | ArrayList getDetail() { 40 | ArrayList list = new ArrayList<>(); 41 | try { 42 | Cursor cursor; 43 | database = dbHelper.getReadableDatabase(); 44 | cursor = database.rawQuery("SELECT * FROM student_details", null); 45 | list.clear(); 46 | if (cursor.getCount() > 0) { 47 | if (cursor.moveToFirst()) { 48 | do { 49 | list.add(cursor.getString(cursor.getColumnIndex("student_name"))); 50 | } while (cursor.moveToNext()); 51 | } 52 | } 53 | cursor.close(); 54 | } catch (Exception e) { 55 | Log.v("Exception", e.toString()); 56 | } 57 | return list; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /app/src/main/java/com/ajts/androidmads/sqliteimpexsample/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.ajts.androidmads.sqliteimpexsample; 2 | 3 | import android.os.Bundle; 4 | import android.os.Environment; 5 | import android.support.v7.app.AppCompatActivity; 6 | import android.view.View; 7 | import android.widget.ArrayAdapter; 8 | import android.widget.EditText; 9 | import android.widget.ListView; 10 | import android.widget.Toast; 11 | 12 | import com.ajts.androidmads.sqliteimpex.SQLiteImporterExporter; 13 | 14 | public class MainActivity extends AppCompatActivity { 15 | 16 | SQLiteImporterExporter sqLiteImporterExporter; 17 | String path = Environment.getExternalStorageDirectory().getAbsolutePath() + "/"; 18 | public static String db = "external_db_android.sqlite"; 19 | 20 | DbQueries dbQueries; 21 | 22 | EditText edtName; 23 | ListView listView; 24 | ArrayAdapter adapter; 25 | 26 | @Override 27 | protected void onCreate(Bundle savedInstanceState) { 28 | super.onCreate(savedInstanceState); 29 | setContentView(R.layout.activity_main); 30 | 31 | sqLiteImporterExporter = new SQLiteImporterExporter(getApplicationContext(), db); 32 | sqLiteImporterExporter.setOnImportListener(new SQLiteImporterExporter.ImportListener() { 33 | @Override 34 | public void onSuccess(String message) { 35 | Toast.makeText(getApplicationContext(), message, Toast.LENGTH_SHORT).show(); 36 | } 37 | 38 | @Override 39 | public void onFailure(Exception exception) { 40 | Toast.makeText(getApplicationContext(), exception.getMessage(), Toast.LENGTH_SHORT).show(); 41 | } 42 | }); 43 | sqLiteImporterExporter.setOnExportListener(new SQLiteImporterExporter.ExportListener() { 44 | @Override 45 | public void onSuccess(String message) { 46 | Toast.makeText(getApplicationContext(), message, Toast.LENGTH_SHORT).show(); 47 | } 48 | 49 | @Override 50 | public void onFailure(Exception exception) { 51 | Toast.makeText(getApplicationContext(), exception.getMessage(), Toast.LENGTH_SHORT).show(); 52 | } 53 | }); 54 | 55 | dbQueries = new DbQueries(getApplicationContext()); 56 | 57 | edtName = (EditText) findViewById(R.id.edtName); 58 | listView = (ListView) findViewById(R.id.listView); 59 | 60 | readDB(); 61 | 62 | findViewById(R.id.btnDBExists).setOnClickListener(new View.OnClickListener() { 63 | @Override 64 | public void onClick(View view) { 65 | if (sqLiteImporterExporter.isDataBaseExists()) { 66 | Toast.makeText(getApplicationContext(), "DB Exists", Toast.LENGTH_SHORT).show(); 67 | } else { 68 | Toast.makeText(getApplicationContext(), "DB Doesn't Exists", Toast.LENGTH_SHORT).show(); 69 | } 70 | } 71 | }); 72 | 73 | findViewById(R.id.btnImportFromAssets).setOnClickListener(new View.OnClickListener() { 74 | @Override 75 | public void onClick(View view) { 76 | try { 77 | sqLiteImporterExporter.importDataBaseFromAssets(); 78 | } catch (Exception e) { 79 | e.printStackTrace(); 80 | } 81 | readDB(); 82 | } 83 | }); 84 | 85 | findViewById(R.id.btnExportToExt).setOnClickListener(new View.OnClickListener() { 86 | @Override 87 | public void onClick(View view) { 88 | try { 89 | sqLiteImporterExporter.exportDataBase(path); 90 | } catch (Exception e) { 91 | e.printStackTrace(); 92 | } 93 | readDB(); 94 | } 95 | }); 96 | 97 | findViewById(R.id.btnImportFromExt).setOnClickListener(new View.OnClickListener() { 98 | @Override 99 | public void onClick(View view) { 100 | try { 101 | sqLiteImporterExporter.importDataBase(path); 102 | } catch (Exception e) { 103 | e.printStackTrace(); 104 | } 105 | readDB(); 106 | 107 | } 108 | }); 109 | 110 | findViewById(R.id.add).setOnClickListener(new View.OnClickListener() { 111 | @Override 112 | public void onClick(View view) { 113 | if (sqLiteImporterExporter.isDataBaseExists()) { 114 | if (edtName.getText().toString().trim().length() > 0) { 115 | dbQueries.open(); 116 | long success = dbQueries.insertDetail(edtName.getText().toString().trim()); 117 | if (success > -1) { 118 | edtName.setText(null); 119 | edtName.clearFocus(); 120 | Toast.makeText(getApplicationContext(), "Successfully Inserted", Toast.LENGTH_LONG).show(); 121 | } else { 122 | Toast.makeText(getApplicationContext(), "Insertion Failed", Toast.LENGTH_LONG).show(); 123 | } 124 | dbQueries.close(); 125 | readDB(); 126 | } else { 127 | edtName.setError("Enter Name"); 128 | } 129 | } else { 130 | edtName.setError("Import DB First"); 131 | } 132 | } 133 | }); 134 | 135 | } 136 | 137 | private void readDB() { 138 | if (sqLiteImporterExporter.isDataBaseExists()) { 139 | dbQueries.open(); 140 | adapter = new ArrayAdapter<>(getApplicationContext(), R.layout.list_item, dbQueries.getDetail()); 141 | listView.setAdapter(adapter); 142 | dbQueries.close(); 143 | } else { 144 | Toast.makeText(getApplicationContext(), "DB Doesn't Exists", Toast.LENGTH_SHORT).show(); 145 | } 146 | } 147 | } 148 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 |