List of usage examples for android.content Context getDatabasePath
public abstract File getDatabasePath(String name);
From source file:org.ttrssreader.controllers.DBHelper.java
public synchronized void initialize(final Context context) { this.contextRef = new WeakReference<>(context); // TODO: Remove leak of context new AsyncTask<Void, Void, Void>() { protected Void doInBackground(Void... params) { // Check if deleteDB is scheduled or if DeleteOnStartup is set if (Controller.getInstance().isDeleteDBScheduled()) { if (deleteDB(context)) { Controller.getInstance().setDeleteDBScheduled(false); initializeDBHelper(); return null; // Don't need to check if DB is corrupted, it is NEW! }// w w w . j a va2 s . c om } // Initialize DB if (!initialized) { initializeDBHelper(); } else if (getOpenHelper() == null) { initializeDBHelper(); } else { return null; // DB was already initialized, no need to check anything. } // Test if DB is accessible, backup and delete if not if (initialized) { Cursor c = null; readLock(true); try { // Try to access the DB c = getOpenHelper().getReadableDatabase() .rawQuery("SELECT COUNT(*) FROM " + TABLE_CATEGORIES, null); c.getCount(); if (c.moveToFirst()) c.getInt(0); } catch (Exception e) { Log.e(TAG, "Database was corrupted, creating a new one...", e); closeDB(); File dbFile = context.getDatabasePath(DATABASE_NAME); if (dbFile.delete()) initializeDBHelper(); ErrorDialog.getInstance( "The Database was corrupted and had to be recreated. If this happened more than once to you please let me know under what circumstances this happened."); } finally { if (c != null && !c.isClosed()) c.close(); readLock(false); } } return null; } }.execute(); }
From source file:com.tct.mail.compose.ComposeActivity.java
public static String getDataColumn(Context context, Uri uri, String selection, String[] selectionArgs) { Cursor cursor = null;/*from www .ja v a 2 s . c o m*/ final String column = "_data"; final String[] projection = { column }; try { cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs, null); if (cursor != null && cursor.moveToFirst()) { final int index = cursor.getColumnIndexOrThrow(column); String path = cursor.getString(index); //[BUGFIX]-Add by TCTNJ,chuang.wang, 2014-07-12,PR728605 Begin if (path != null && path.endsWith("RAW")) { //[BUGFIX]-Add by TCTNJ,chuang.wang, 2014-07-12,PR728605 END List<String> segments = uri.getPathSegments(); String dbName = segments.get(0); String id = segments.get(1); path = context.getDatabasePath(dbName + "_att") + "/" + id; } return path; } //[BUGFIX]-Mod-BEGIN by TSNJ,yong.tao,1/27/2015, PR-913357 } catch (Exception e) { //[BUGFIX]-Mod-END by TSNJ,yong.tao } finally { if (cursor != null) cursor.close(); } return null; }