Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support minSDK 14 #33

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ buildscript {
ext.buildConfig = [
compileSdk : 29,
targetSdk : 29,
minSdk : 16,
minSdk : 14,
buildTools : '29.0.2',
gradlePlugin : '3.5.3'
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteClosable;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.os.Build;
import android.os.Build.VERSION_CODES;
import android.text.TextUtils;
import androidx.annotation.Nullable;
import com.jaredrummler.android.device.DeviceName.DeviceInfo;
Expand Down Expand Up @@ -150,7 +152,16 @@ private void create() throws SQLException {
close(); // Close the empty database
transferDatabaseAsset(); // Copy the database from assets to the application's database dir
} catch (IOException e) {
throw new SQLException("Error creating " + NAME + " database", e);
if (Build.VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN) {
throw new SQLException("Error creating " + NAME + " database", e);
} else {
try {
//noinspection UnnecessaryInitCause
throw new SQLException("Error creating " + NAME + " database").initCause(e);
} catch (Throwable throwable) {
throw new SQLException("Error creating " + NAME + " database");
}
}
}
}

Expand All @@ -167,10 +178,24 @@ private void transferDatabaseAsset() throws IOException {
close(input);
}

private void close(Closeable closeable) {
if (closeable != null) {
private void close(Object closeable) {
if (Build.VERSION.SDK_INT < VERSION_CODES.JELLY_BEAN) {
if (closeable instanceof Cursor) {
((Cursor) closeable).close();
return;
}
if (closeable instanceof SQLiteClosable) {
// SQLiteDatabase implements SQLiteClosable since at least 1.6/API 4/Donut
((SQLiteClosable) closeable).releaseReference();
return;
}

// InputStream, OutputStream implement Closeable since at least 2.3/API 9/Gingerbread
}

if (closeable instanceof Closeable) {
try {
closeable.close();
((Closeable) closeable).close();
} catch (IOException ignored) {
}
}
Expand Down