I need to check if a file (with unknown extension) is a valid SQLite database. The db file is stored on the SD card. I need to import a database into my application. But if the user creates a file with the same name as in the database with any extension, the file is still accepted by the code when searching only for the name. Is there a quick way to check if sqlite db stored on a memory card is working correctly. I used this code, but it still accepts an arbitrary file with the same name as db.
String path = Environment.getExternalStorageDirectory().getPath() + "/FOLDER/DB_FILE";
SQLiteDatabase database;
database = SQLiteDatabase.openDatabase(path, null, SQLiteDatabase.OPEN_READONLY);
if (database == null) {
Toast.makeText(getApplicationContext(), "Error: Incorrect/Corrupted File", Toast.LENGTH_SHORT).show();
return;
} else {Proceed with code here}
source
share