本文整理汇总了Java中android.content.Context.getDatabasePath方法的典型用法代码示例。如果您正苦于以下问题:Java Context.getDatabasePath方法的具体用法?Java Context.getDatabasePath怎么用?Java Context.getDatabasePath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.content.Context
的用法示例。
在下文中一共展示了Context.getDatabasePath方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: ApnDatabase
import android.content.Context; //导入方法依赖的package包/类
private ApnDatabase(final Context context) throws IOException {
this.context = context;
File dbFile = context.getDatabasePath(DATABASE_NAME);
if (!dbFile.getParentFile().exists() && !dbFile.getParentFile().mkdir()) {
throw new IOException("couldn't make databases directory");
}
Util.copy(context.getAssets().open(ASSET_PATH, AssetManager.ACCESS_STREAMING),
new FileOutputStream(dbFile));
try {
this.db = SQLiteDatabase.openDatabase(context.getDatabasePath(DATABASE_NAME).getPath(),
null,
SQLiteDatabase.OPEN_READONLY | SQLiteDatabase.NO_LOCALIZED_COLLATORS);
} catch (SQLiteException e) {
throw new IOException(e);
}
}
示例2: DatabaseHandler
import android.content.Context; //导入方法依赖的package包/类
public DatabaseHandler(Context context,String pass,Boolean isCreated) throws Exception {
super(context,DATABASE_NAME,null,DATABASE_VERSION);
this.context=context;
File databaseFile=context.getDatabasePath(DATABASE_NAME+".db");
if(!isCreated){
Log.d(TAG, "DatabaseHandler: im here");
if(databaseFile.mkdirs()){
Log.d(TAG, "DatabaseHandler: created dir");
}else{
throw new Exception("Cannot create dir");
}
databaseFile.delete();
Log.d(TAG,"database was not present, so created");
mDB=SQLiteDatabase.openOrCreateDatabase(databaseFile,pass,null);
mDB.execSQL(FeedReaderContract.CREATE_TABLE_SECRING);
mDB.execSQL(FeedReaderContract.CREATE_TABLE_PUBRING);
close();
mDB.close();
}else{
Log.d(TAG, "database was present, so opened");
mDB=SQLiteDatabase.openDatabase(databaseFile.getPath(),pass,null,0);
}
}
示例3: DatabaseHelper
import android.content.Context; //导入方法依赖的package包/类
private DatabaseHelper(Context context) {
super(context, DB_NAME, null, DB_VERSION);
prefs = PreferenceManager.getDefaultSharedPreferences(context);
if (!once) {
once = true;
File dbfile = context.getDatabasePath(DB_NAME);
if (dbfile.exists()) {
Log.w(TAG, "Deleting " + dbfile);
dbfile.delete();
}
File dbjournal = context.getDatabasePath(DB_NAME + "-journal");
if (dbjournal.exists()) {
Log.w(TAG, "Deleting " + dbjournal);
dbjournal.delete();
}
}
}
示例4: saveDBFromAssetsToData
import android.content.Context; //导入方法依赖的package包/类
private static void saveDBFromAssetsToData(Context context, String dbfilename) throws Exception {
File newfile = context.getDatabasePath(dbfilename);
if (newfile.exists()) {
return;
}
newfile.createNewFile();
InputStream initialStream = context.getAssets().open("databases/" + dbfilename);
OutputStream outStream = new FileOutputStream(newfile);
byte[] buffer = new byte[8 * 1024];
int bytesRead;
while ((bytesRead = initialStream.read(buffer)) != -1) {
outStream.write(buffer, 0, bytesRead);
}
initialStream.close();
outStream.close();
}
示例5: copyAttachedDatabase
import android.content.Context; //导入方法依赖的package包/类
public void copyAttachedDatabase(Context context, String databaseName) {
final File dbPath = context.getDatabasePath(databaseName);
// If the database already exists, return
if (dbPath.exists()) {
return;
}
// Make sure we have a path to the file
dbPath.getParentFile().mkdirs();
// Try to copy database file
try {
final InputStream inputStream = context.getAssets().open(databaseName);
final OutputStream output = new FileOutputStream(dbPath);
byte[] buffer = new byte[8192];
int length;
while ((length = inputStream.read(buffer, 0, 8192)) > 0) {
output.write(buffer, 0, length);
}
output.flush();
output.close();
inputStream.close();
}
catch (IOException e) {
Log.e("Failed to open file", e);
}
}
示例6: tearDown
import android.content.Context; //导入方法依赖的package包/类
@After
public void tearDown() {
Context ctxt=InstrumentationRegistry.getTargetContext();
File db=ctxt.getDatabasePath(DB_NAME);
if (db.exists()) {
db.delete();
}
File journal=new File(db.getParentFile(), DB_NAME+"-journal");
if (journal.exists()) {
journal.delete();
}
}
示例7: douDbHelper
import android.content.Context; //导入方法依赖的package包/类
@Provides
@DouAppScope
public DouDbHelper douDbHelper(@ApplicationContext Context context) {
File f = context.getDatabasePath(DouDbHelper.DATABASE_NAME);
f.getParentFile().mkdirs();
DouDbHelper helper = new DouDbHelper(context, f.getPath());
helper.getReadableDatabase().loadExtension(Config.EXTENSIONS_LIB);
return helper;
}
示例8: loadDefault
import android.content.Context; //导入方法依赖的package包/类
/**
* 读取输入流, 创建数据库文件.
*
* @param context 上下文
* @param targetDbName 目标数据库名称
* @param is 文件输入流
*/
@Deprecated
public static void loadDefault(Context context, String targetDbName, InputStream is)
{
File file = context.getDatabasePath(targetDbName);
if (file.exists())
{
// 文件存在, 直接路过此步骤.
return;
}
Log.I(TAG, "Load default database [" + targetDbName + "]");
FileUtils.writeFile(file, is, false);
}
示例9: importDB
import android.content.Context; //导入方法依赖的package包/类
static boolean importDB(Context context) {
unInitializeDb();
try {
File sd = Environment.getExternalStorageDirectory();
if (sd.canWrite()) {
File backupDB = new File(sd, BACKUP_DB_PATH);
File currentDB = context.getDatabasePath(DatabaseContract.DATABASE_NAME);
try (FileInputStream fis = new FileInputStream(backupDB)) {
try (FileOutputStream fos = new FileOutputStream(currentDB)) {
FileChannel src = fis.getChannel();
FileChannel dst = fos.getChannel();
dst.transferFrom(src, 0, src.size());
src.close();
dst.close();
fis.close();
fos.close();
}
}
initializeDb(context);
return true;
}
} catch (Exception e) {
Log.e("GM/importDb", e.toString());
}
initializeDb(context);
return false;
}
示例10: exportDB
import android.content.Context; //导入方法依赖的package包/类
static Boolean exportDB(Context context) {
unInitializeDb();
try {
File sd = Environment.getExternalStorageDirectory();
if (sd.canWrite()) {
File currentDB = context.getDatabasePath(DatabaseContract.DATABASE_NAME);
File backupDB = new File(sd, BACKUP_DB_PATH);
try (FileInputStream fis = new FileInputStream(currentDB)) {
try (FileOutputStream fos = new FileOutputStream(backupDB)) {
FileChannel src = fis.getChannel();
FileChannel dst = fos.getChannel();
dst.transferFrom(src, 0, src.size());
src.close();
dst.close();
fis.close();
fos.close();
}
}
initializeDb(context);
return true;
}
} catch (Exception e) {
Log.e("GM/exportDb", e.toString());
}
initializeDb(context);
return false;
}
示例11: getDatabase
import android.content.Context; //导入方法依赖的package包/类
@Override
public File getDatabase(Context context, String id) {
return context.getDatabasePath(id + ".db");
}
示例12: DeleteOnDowngradeSQLiteOpenHelper
import android.content.Context; //导入方法依赖的package包/类
public DeleteOnDowngradeSQLiteOpenHelper(Context context, String name, CursorFactory factory, int version) {
super(context, name, factory, version);
mDatabaseFile = context.getDatabasePath(name);
}
示例13: SipProfilesHelper
import android.content.Context; //导入方法依赖的package包/类
SipProfilesHelper(Context ctxt) {
mContext = ctxt;
databaseFile = ctxt.getDatabasePath(SipManager.AUTHORITY);
}
示例14: fixDatabasePatch
import android.content.Context; //导入方法依赖的package包/类
public static String fixDatabasePatch(Context context){
File f = context.getDatabasePath(DouDbHelper.DATABASE_NAME);
f.getParentFile().mkdirs();
return f.getPath();
}
示例15: doesDatabaseExist
import android.content.Context; //导入方法依赖的package包/类
private static boolean doesDatabaseExist(Context context, String dbName) {
File dbFile = context.getDatabasePath(dbName);
return dbFile.exists();
}