List of usage examples for android.content ContentProviderClient getLocalContentProvider
public @Nullable ContentProvider getLocalContentProvider()
From source file:can.yrt.onebusaway.backup.Backup.java
/** * Performs a restore from the SD card.//from ww w .j ava2s .c o m * * @param context */ public static void restore(Context context) throws IOException { File dbPath = getDB(context); File backupPath = getBackup(context); // At least here we can decide that the database is closed. ContentProviderClient client = null; try { client = context.getContentResolver().acquireContentProviderClient(ObaContract.AUTHORITY); ObaProvider provider = (ObaProvider) client.getLocalContentProvider(); provider.closeDB(); FileUtils.copyFile(backupPath, dbPath); } finally { if (client != null) { client.release(); } } }
From source file:org.totschnig.myexpenses.provider.DbUtils.java
public static Result backup(File backupDir) { cacheEventData();//from w w w . j a v a 2 s . com ContentResolver resolver = MyApplication.getInstance().getContentResolver(); ContentProviderClient client = resolver.acquireContentProviderClient(TransactionProvider.AUTHORITY); TransactionProvider provider = (TransactionProvider) client.getLocalContentProvider(); Result result = provider.backup(backupDir); client.release(); return result; }
From source file:org.totschnig.myexpenses.provider.DbUtils.java
public static boolean restore(File backupFile) { boolean result = false; MyApplication app = MyApplication.getInstance(); try {// w ww. j ava 2s . co m DailyAutoBackupScheduler.cancelAutoBackup(app); PlanExecutor.cancelPlans(app); Account.clear(); PaymentMethod.clear(); if (backupFile.exists()) { ContentResolver resolver = app.getContentResolver(); ContentProviderClient client = resolver.acquireContentProviderClient(TransactionProvider.AUTHORITY); TransactionProvider provider = (TransactionProvider) client.getLocalContentProvider(); result = provider.restore(backupFile); client.release(); } } catch (Exception e) { AcraHelper.report(e); } app.initPlanner(); DailyAutoBackupScheduler.updateAutoBackupAlarms(app); return result; }
From source file:dev.dworks.apps.anexplorer.provider.ExternalStorageProvider.java
public static void updateVolumes(Context context) { final ContentProviderClient client = ContentProviderClientCompat.acquireUnstableContentProviderClient( context.getContentResolver(), ExternalStorageProvider.AUTHORITY); try {/*from ww w . ja v a 2 s . c o m*/ ((ExternalStorageProvider) client.getLocalContentProvider()).updateVolumes(); } finally { ContentProviderClientCompat.releaseQuietly(client); } }
From source file:dev.drsoran.moloko.sync.SyncAdapter.java
private RtmProvider ensureTransactionSupport(ContentProviderClient provider) { if (provider.getLocalContentProvider() instanceof RtmProvider) return (RtmProvider) provider.getLocalContentProvider(); else//from w w w . jav a 2 s . c om throw new IllegalStateException("no ContentProvider transaction support"); }
From source file:com.mobileaffairs.seminar.videolib.VideoLibSyncAdapter.java
@Override public void onPerformSync(Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) {/*from www . ja va 2 s. c om*/ String videosJson = readVideosFromRemoteService(); try { JSONArray jsonArray = new JSONArray(videosJson); Log.i("SyncAdapter", "Number of entries " + jsonArray.length()); for (int i = 0; i < jsonArray.length(); i++) { JSONObject jsonObject = jsonArray.getJSONObject(i); Cursor cs = provider.getLocalContentProvider().query( Uri.parse(VideoLibContentProvider.CONTENT_URI + "/" + jsonObject.getString("id")), null, null, null, null); long count = cs.getCount(); cs.close(); if (count == 0) { ContentValues values = new ContentValues(); values.put("_id", jsonObject.getString("id")); values.put("title", jsonObject.getString("title")); values.put("duration", jsonObject.getString("duration")); values.put("videoUrl", jsonObject.getString("url")); byte[] imageBytes = readImage(jsonObject.getString("thumbnail_small")); if (imageBytes != null && imageBytes.length > 0) { values.put("thumbnail", imageBytes); } provider.getLocalContentProvider().insert(VideoLibContentProvider.CONTENT_URI, values); } syncResult.fullSyncRequested = true; } } catch (Exception e) { e.printStackTrace(); } }
From source file:com.robotoworks.mechanoid.sqlite.SQuery.java
/** * <p>Select records using this query</p> * @param uri The ContentProvider Uri to query for * @param sortOrder The order by clause//w w w .jav a 2s . c o m * @return The results as active records */ public <T extends ActiveRecord> List<T> select(Uri uri, String sortOrder) { ContentResolver resolver = Mechanoid.getContentResolver(); ContentProviderClient client = resolver.acquireContentProviderClient(uri); MechanoidContentProvider provider = (MechanoidContentProvider) client.getLocalContentProvider(); List<T> records = provider.selectRecords(uri, this, sortOrder); return records; }
From source file:com.robotoworks.mechanoid.sqlite.SQuery.java
/** * <p>Select records using this query</p> * @param uri The ContentProvider Uri to query for * @return The results as active records *///from www . j a v a2 s .co m public <T extends ActiveRecord> List<T> select(Uri uri) { ContentResolver resolver = Mechanoid.getContentResolver(); ContentProviderClient client = resolver.acquireContentProviderClient(uri); MechanoidContentProvider provider = (MechanoidContentProvider) client.getLocalContentProvider(); List<T> records = provider.selectRecords(uri, this, null); return records; }
From source file:com.robotoworks.mechanoid.sqlite.SQuery.java
/** * <p>Select the first record from the results of using this query</p> * @param uri The ContentProvider Uri to query for * @param sortOrder The order by clause//from ww w . j av a 2 s. c o m * @return The results as active records */ public <T extends ActiveRecord> T selectFirst(Uri uri, String sortOrder) { ContentResolver resolver = Mechanoid.getContentResolver(); ContentProviderClient client = resolver.acquireContentProviderClient(uri); MechanoidContentProvider provider = (MechanoidContentProvider) client.getLocalContentProvider(); List<T> records = provider.selectRecords(uri, this, sortOrder); if (records.size() > 0) { return records.get(0); } else { return null; } }
From source file:com.robotoworks.mechanoid.sqlite.SQuery.java
/** * <p>Select the first record from the results of using this query</p> * @param uri The ContentProvider Uri to query for * @return The results as active records *///from www . j ava 2 s .c o m public <T extends ActiveRecord> T selectFirst(Uri uri) { ContentResolver resolver = Mechanoid.getContentResolver(); ContentProviderClient client = resolver.acquireContentProviderClient(uri); MechanoidContentProvider provider = (MechanoidContentProvider) client.getLocalContentProvider(); List<T> records = provider.selectRecords(uri, this, null); if (records.size() > 0) { return records.get(0); } else { return null; } }