本文整理汇总了Java中android.content.Context.deleteDatabase方法的典型用法代码示例。如果您正苦于以下问题:Java Context.deleteDatabase方法的具体用法?Java Context.deleteDatabase怎么用?Java Context.deleteDatabase使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.content.Context
的用法示例。
在下文中一共展示了Context.deleteDatabase方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createDatabase
import android.content.Context; //导入方法依赖的package包/类
public static Database createDatabase(Context context, String dbName, String password) {
if (!loadedLibs) {
loadedLibs = true;
SQLiteDatabase.loadLibs(context);
}
SQLiteDatabase sqLiteDatabase;
if (dbName == null) {
sqLiteDatabase = SQLiteDatabase.create(null, password);
} else {
File dbFile = context.getDatabasePath(dbName);
dbFile.getParentFile().mkdir();
context.deleteDatabase(dbName);
sqLiteDatabase = SQLiteDatabase.openOrCreateDatabase(dbFile, password, null);
}
return new EncryptedDatabase(sqLiteDatabase);
}
示例2: clearWebViewAllCache
import android.content.Context; //导入方法依赖的package包/类
static void clearWebViewAllCache(Context context, WebView webView) {
try {
AgentWebConfig.removeAllCookies(null);
webView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
context.deleteDatabase("webviewCache.db");
context.deleteDatabase("webview.db");
webView.clearCache(true);
webView.clearHistory();
webView.clearFormData();
clearCacheFolder(new File(AgentWebConfig.getCachePath(context)), 0);
} catch (Exception ignore) {
//ignore.printStackTrace();
if (AgentWebConfig.DEBUG)
ignore.printStackTrace();
}
}
示例3: doMigration
import android.content.Context; //导入方法依赖的package包/类
static void doMigration(Context context, InboxManager inboxManager) {
try {
if (doesDatabaseExist(context, DBMigratorSQLiteHelper.DATABASE_NAME)) {
DBMigratorSQLiteHelper dbHelper = new DBMigratorSQLiteHelper(context);
if (dbHelper != null) {
Cursor cursor = getTopEntryCursor(dbHelper.getWritableDatabase());
while (cursor.moveToNext()) {
insertMessageFromEntry(inboxManager, cursor);
}
cursor.close();
dbHelper.close();
try {
context.deleteDatabase(DBMigratorSQLiteHelper.DATABASE_NAME);
} catch (Exception e) {
}
}
}
} catch (Exception e2) {
}
}
示例4: deleteDatabases
import android.content.Context; //导入方法依赖的package包/类
private static void deleteDatabases(Context context) {
String[] dbList = context.databaseList();
if (dbList != null) {
for (String file : dbList) {
if (!context.deleteDatabase(file)) {
Log.e(TAG, "Unable to delete database " + file + ".");
}
}
}
}
示例5: testCreateDb
import android.content.Context; //导入方法依赖的package包/类
/**
* Tests that the database exists and the quotes table has the correct columns.
*/
@Test
public void testCreateDb() throws Exception {
// build a HashSet of all of the table names we wish to look for
// Note that there will be another table in the DB that stores the
// Android metadata (db version information)
final HashSet<String> tableNameHashSet = new HashSet<>();
tableNameHashSet.add(FavoritesContract.FavoriteColumns.FAVORITE_MOVIES_TBL);
tableNameHashSet.add(FavoritesContract.FavoriteColumns.FAVORITE_TV_SHOWS_TBL);
tableNameHashSet.add(FavoritesContract.FavoriteColumns.FAVORITE_PERSON_TBL);
Context appContext = InstrumentationRegistry.getTargetContext();
appContext.deleteDatabase(FavoritesDbHelper.DATABASE_NAME);
SQLiteDatabase db = new FavoritesDbHelper(appContext).getWritableDatabase();
assertEquals(true, db.isOpen());
// have we created the tables we want?
Cursor c = db.rawQuery("SELECT name FROM sqlite_master WHERE type='table'", null);
assertTrue("Error: This means that the database has not been created correctly",
c.moveToFirst());
// verify that the tables have been created
do {
tableNameHashSet.remove(c.getString(0));
} while( c.moveToNext() );
// if this fails, it means that your database doesn't contain the tables
assertTrue("Error: Your database was created without the tables", tableNameHashSet.isEmpty());
// now, do our tables contain the correct columns?
c = db.rawQuery("PRAGMA table_info(" + FavoritesContract.FavoriteColumns.FAVORITE_MOVIES_TBL + ")", null);
assertTrue("Error: This means that we were unable to query the database for table information.",
c.moveToFirst());
// Build a HashSet of all of the column names we want to look for
final HashSet<String> locationColumnHashSet = new HashSet<>();
locationColumnHashSet.add(FavoritesContract.FavoriteColumns._ID);
locationColumnHashSet.add(FavoritesContract.FavoriteColumns.COLUMN_MOVIE_ID);
locationColumnHashSet.add(FavoritesContract.FavoriteColumns.COLUMN_TITLE);
locationColumnHashSet.add(FavoritesContract.FavoriteColumns.COLUMN_PLOT);
locationColumnHashSet.add(FavoritesContract.FavoriteColumns.COLUMN_POSTER_PATH);
locationColumnHashSet.add(FavoritesContract.FavoriteColumns.COLUMN_YEAR);
locationColumnHashSet.add(FavoritesContract.FavoriteColumns.COLUMN_DURATION);
locationColumnHashSet.add(FavoritesContract.FavoriteColumns.COLUMN_VOTE_AVERAGE);
locationColumnHashSet.add(FavoritesContract.FavoriteColumns.COLUMN_VOTE_COUNT);
locationColumnHashSet.add(FavoritesContract.FavoriteColumns.COLUMN_BACKGROUND_PATH);
locationColumnHashSet.add(FavoritesContract.FavoriteColumns.COLUMN_ORIGINAL_LANGUAGE);
locationColumnHashSet.add(FavoritesContract.FavoriteColumns.COLUMN_STATUS);
locationColumnHashSet.add(FavoritesContract.FavoriteColumns.COLUMN_IMDB_ID);
locationColumnHashSet.add(FavoritesContract.FavoriteColumns.COLUMN_BUDGET);
locationColumnHashSet.add(FavoritesContract.FavoriteColumns.COLUMN_REVENUE);
locationColumnHashSet.add(FavoritesContract.FavoriteColumns.COLUMN_HOMEPAGE);
int columnNameIndex = c.getColumnIndex("name");
do {
String columnName = c.getString(columnNameIndex);
locationColumnHashSet.remove(columnName);
} while(c.moveToNext());
c.close();
// if this fails, it means that your database doesn't contain all of the required columns
assertTrue("Error: The database doesn't contain all of the required columns",
locationColumnHashSet.isEmpty());
db.close();
}
示例6: SqlLiteHelper
import android.content.Context; //导入方法依赖的package包/类
/**
* Constructor used to create database if database does not already exist.
* Will delete existing Hexis database if PURGE_DATABASE is true
*
* @param context Program context
*/
public SqlLiteHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
// Delete Hexis database if PURGE_DATABASE is true
if (PURGE_DATABASE) {
// For testing purposes we need to delete the database so onCreate will be called
context.deleteDatabase(DATABASE_NAME);
// Delete actual database file from filesystem
context.deleteFile(DATABASE_NAME);
}
}
示例7: purgeDatabase
import android.content.Context; //导入方法依赖的package包/类
public void purgeDatabase(Context context) {
context.deleteDatabase(DATABASE_NAME);
}
示例8: Remove
import android.content.Context; //导入方法依赖的package包/类
private void Remove(@NonNull Context context) {
context.deleteDatabase(DATABASE_NAME);
}
示例9: removeDatabaseFor
import android.content.Context; //导入方法依赖的package包/类
public static void removeDatabaseFor(Context context, int aid) {
dbHelperMap.remove(aid);
context.deleteDatabase(DBHelper.getDatabaseFileName(aid));
}
示例10: cleanDatabaseByName
import android.content.Context; //导入方法依赖的package包/类
/**
* * 按名字清除本应用数据库 * *
*/
public static void cleanDatabaseByName(Context context, String dbName) {
context.deleteDatabase(dbName);
}
示例11: deleteTheDatabase
import android.content.Context; //导入方法依赖的package包/类
private void deleteTheDatabase() {
Context appContext = InstrumentationRegistry.getTargetContext();
appContext.deleteDatabase(FavoritesDbHelper.DATABASE_NAME);
}
示例12: cleanDatabaseByName
import android.content.Context; //导入方法依赖的package包/类
/** * 按名字清除本应用数据库 * * @param context * @param dbName */
public static void cleanDatabaseByName(Context context, String dbName) {
context.deleteDatabase(dbName);
}
示例13: deleteDatabase
import android.content.Context; //导入方法依赖的package包/类
public static void deleteDatabase(Context context) {
context.deleteDatabase(DATABASE_NAME);
}
示例14: deleteDatabase
import android.content.Context; //导入方法依赖的package包/类
static void deleteDatabase(Context context) {
context.deleteDatabase(DATABASE_NAME);
}
示例15: cleanInternalDbByName
import android.content.Context; //导入方法依赖的package包/类
/**
* 根据名称清除数据库
* <p>/data/data/com.xxx.xxx/databases/dbName</p>
*
* @param dbName 数据库名称
* @return {@code true}: 清除成功<br>{@code false}: 清除失败
*/
public static boolean cleanInternalDbByName(Context context, String dbName) {
return context.deleteDatabase(dbName);
}