本文整理匯總了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);
}