List of usage examples for android.provider DocumentsContract buildRootsUri
public static Uri buildRootsUri(String authority)
From source file:com.example.android.storageprovider.MyCloudFragment.java
@Override public boolean onOptionsItemSelected(MenuItem item) { if (item.getItemId() == R.id.sample_action) { toggleLogin();//w w w .j a v a 2 s . c o m item.setTitle(mLoggedIn ? R.string.log_out : R.string.log_in); // BEGIN_INCLUDE(notify_change) // Notify the system that the status of our roots has changed. This will trigger // a call to MyCloudProvider.queryRoots() and force a refresh of the system // picker UI. It's important to call this or stale results may persist. getActivity().getContentResolver().notifyChange(DocumentsContract.buildRootsUri(AUTHORITY), null, false); // END_INCLUDE(notify_change) } return true; }
From source file:com.raspi.chatapp.util.storage.file.LocalStorageProvider.java
/** * Check to see if we are missing the Storage permission group. In those cases, we cannot access local files and * must invalidate any root URIs currently available. * * @param context The current Context/* w w w . jav a 2 s . com*/ * @return whether the permission has been granted it is safe to proceed */ static boolean isMissingPermission(@Nullable Context context) { if (context == null) { return true; } if (ContextCompat.checkSelfPermission(context, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { // Make sure that our root is invalidated as apparently we lost permission context.getContentResolver() .notifyChange(DocumentsContract.buildRootsUri(LocalStorageProvider.AUTHORITY), null); return true; } return false; }
From source file:org.alfresco.mobile.android.application.providers.storage.StorageAccessDocumentsProvider.java
@Override public Cursor queryRoots(String[] projection) throws FileNotFoundException { final DocumentFolderCursor rootCursor = new DocumentFolderCursor(resolveRootProjection(projection)); final Uri uri = DocumentsContract.buildRootsUri(mAuthority); try {/*www .ja v a2s . co m*/ for (int i = 0; i < accountsIndex.size(); i++) { addRootRow(rootCursor, accountsIndex.get(accountsIndex.keyAt(i))); } } catch (Exception e) { rootCursor.setErrorInformation("Error : " + e.getMessage()); rootCursor.setNotificationUri(getContext().getContentResolver(), uri); getContext().getContentResolver().notifyChange(uri, null); Log.w(TAG, Log.getStackTraceString(e)); } return rootCursor; }
From source file:cn.edu.wyu.documentviewer.RootsCache.java
/** * Bring up requested provider and query for all active roots. *//* w ww .ja v a 2 s . c o m*/ private Collection<RootInfo> loadRootsForAuthority(ContentResolver resolver, String authority) { if (DEBUG) Log.d(TAG, "Loading roots for " + authority); synchronized (mObservedAuthorities) { if (mObservedAuthorities.add(authority)) { // Watch for any future updates final Uri rootsUri = DocumentsContract.buildRootsUri(authority); mContext.getContentResolver().registerContentObserver(rootsUri, true, mObserver); } } final List<RootInfo> roots = Lists.newArrayList(); final Uri rootsUri = DocumentsContract.buildRootsUri(authority); ContentProviderClient client = null; Cursor cursor = null; try { client = DocumentsApplication.acquireUnstableProviderOrThrow(resolver, authority); cursor = client.query(rootsUri, null, null, null, null); while (cursor.moveToNext()) { final RootInfo root = RootInfo.fromRootsCursor(authority, cursor); roots.add(root); } } catch (Exception e) { Log.w(TAG, "Failed to load some roots from " + authority + ": " + e); } finally { IOUtils.closeQuietly(cursor); ContentProviderClient.releaseQuietly(client); } return roots; }