当前位置: 首页>>代码示例>>Java>>正文


Java Context.getDatabasePath方法代码示例

本文整理汇总了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);
  }
}
 
开发者ID:XecureIT,项目名称:PeSanKita-android,代码行数:21,代码来源:ApnDatabase.java

示例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);
    }

}
 
开发者ID:mosamabinomar,项目名称:RootPGPExplorer,代码行数:26,代码来源:DatabaseHandler.java

示例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();
        }
    }
}
 
开发者ID:miankai,项目名称:MKAPP,代码行数:21,代码来源:DatabaseHelper.java

示例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();
}
 
开发者ID:MobClub,项目名称:BBSSDK-for-Android,代码行数:17,代码来源:LocationHelper.java

示例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);
	}
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:32,代码来源:DatabaseHelper.java

示例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();
  }
}
 
开发者ID:commonsguy,项目名称:cwac-saferoom,代码行数:16,代码来源:RekeyTest.java

示例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;
}
 
开发者ID:graviton57,项目名称:DOUSalaries,代码行数:10,代码来源:DatabaseModule.java

示例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);
}
 
开发者ID:benniaobuguai,项目名称:android-project-gallery,代码行数:22,代码来源:DatabaseLoader.java

示例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;
    }
 
开发者ID:xRahul,项目名称:GroupingMessages,代码行数:32,代码来源:DatabaseBridge.java

示例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;
    }
 
开发者ID:xRahul,项目名称:GroupingMessages,代码行数:32,代码来源:DatabaseBridge.java

示例11: getDatabase

import android.content.Context; //导入方法依赖的package包/类
@Override
public File getDatabase(Context context, String id) {
    return context.getDatabasePath(id + ".db");
}
 
开发者ID:philipwhiuk,项目名称:q-mail,代码行数:5,代码来源:StorageManager.java

示例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);
}
 
开发者ID:archos-sa,项目名称:aos-MediaLib,代码行数:5,代码来源:DeleteOnDowngradeSQLiteOpenHelper.java

示例13: SipProfilesHelper

import android.content.Context; //导入方法依赖的package包/类
SipProfilesHelper(Context ctxt) {
    mContext = ctxt;
    databaseFile = ctxt.getDatabasePath(SipManager.AUTHORITY);
}
 
开发者ID:treasure-lau,项目名称:CSipSimple,代码行数:5,代码来源:SipProfilesHelper.java

示例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();
}
 
开发者ID:graviton57,项目名称:DOUSalaries,代码行数:6,代码来源:TestUtils.java

示例15: doesDatabaseExist

import android.content.Context; //导入方法依赖的package包/类
private static boolean doesDatabaseExist(Context context, String dbName) {
    File dbFile = context.getDatabasePath(dbName);
    return dbFile.exists();
}
 
开发者ID:AmulaySoftGroup,项目名称:TaBeTa,代码行数:5,代码来源:InternalDB.java


注:本文中的android.content.Context.getDatabasePath方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。