Code example for Uri

Methods: getAuthority, getScheme

0
      TestCursor returnCursor = getCursor(uri);
      if (returnCursor == null) {
        return null; 
      } 
 
      returnCursor.setQuery(uri, projection, selection, selectionArgs,
          sortOrder);
      return returnCursor;
    } 
  } 
 
  @Implementation 
  public final int delete(Uri url, String where, String[] selectionArgs) {
    ContentProvider provider = getProvider(url);
    if (provider != null) {
      return provider.delete(url, where, selectionArgs);
    } else { 
      DeleteStatement deleteStatement = new DeleteStatement(url, where, selectionArgs);
      deleteStatements.add(deleteStatement);
      return 1; 
    } 
  } 
 
  @Implementation 
  public final int bulkInsert(Uri url, ContentValues[] values) {
    ContentProvider provider = getProvider(url);
    if (provider != null) {
      return provider.bulkInsert(url, values);
    } else { 
      return 0; 
    } 
  } 
 
  @Implementation 
  public void notifyChange(Uri uri, ContentObserver observer, boolean syncToNetwork) {
    notifiedUris.add(new NotifiedUri(uri, observer, syncToNetwork));
 
    // TODO does not support multiple observers for a URI 
    ContentObserver obs = contentObservers.get(uri);
    if ( obs != null && obs != observer  ) {
      obs.dispatchChange( false, uri );
    } 
    if ( observer != null && observer.deliverSelfNotifications() ) {
      observer.dispatchChange( true, uri );
    } 
  } 
 
  @Implementation 
  public void notifyChange(Uri uri, ContentObserver observer) {
    notifyChange(uri, observer, false);
  } 
 
  @Implementation 
  public ContentProviderResult[] applyBatch(String authority, ArrayList<ContentProviderOperation> operations) throws OperationApplicationException {
    ContentProvider provider = providers.get(authority);
    if (provider != null) {
      return provider.applyBatch(operations);
    } else { 
      contentProviderOperations.put(authority, operations);
      return contentProviderResults;
    } 
  } 
 
  @Implementation 
  public static void requestSync(Account account, String authority, Bundle extras) {
    validateSyncExtrasBundle(extras);
    Status status = getStatus(account, authority, true);
    status.syncRequests++;
    status.syncExtras = extras;
  } 
 
  @Implementation 
  public static void setIsSyncable(Account account, String authority, int syncable) {
    getStatus(account, authority, true).state = syncable;
  } 
 
  @Implementation 
  public static int getIsSyncable(Account account, String authority) {
    return getStatus(account, authority, true).state;
  } 
 
  @Implementation 
  public static boolean getSyncAutomatically(Account account, String authority) {
    return getStatus(account, authority, true).syncAutomatically;
  } 
 
  @Implementation 
  public static void setSyncAutomatically(Account account, String authority, boolean sync) {
    getStatus(account, authority, true).syncAutomatically = sync;
  } 
 
  @Implementation 
  public static void addPeriodicSync(Account account, String authority, Bundle extras,
                     long pollFrequency) {
 
    validateSyncExtrasBundle(extras);
    getStatus(account, authority, true).syncs.add(new PeriodicSync(account, authority, extras, pollFrequency));
  } 
 
  @Implementation 
  public static void removePeriodicSync(Account account, String authority, Bundle extras) {
    validateSyncExtrasBundle(extras);
    Status status = getStatus(account, authority);
    if (status != null) status.syncs.clear();
  } 
 
  @Implementation 
  public static List<PeriodicSync> getPeriodicSyncs(Account account, String authority) {
    return getStatus(account, authority, true).syncs;
  } 
 
  @Implementation 
  public static void validateSyncExtrasBundle(Bundle extras) {
    for (String key : extras.keySet()) {
      Object value = extras.get(key);
      if (value == null) continue;
      if (value instanceof Long) continue;
      if (value instanceof Integer) continue;
      if (value instanceof Boolean) continue;
      if (value instanceof Float) continue;
      if (value instanceof Double) continue;
      if (value instanceof String) continue;
      if (value instanceof Account) continue;
      throw new IllegalArgumentException("unexpected value type: "
          + value.getClass().getName());
    } 
  } 
 
  @Implementation 
  public static void setMasterSyncAutomatically(boolean sync) {
    masterSyncAutomatically = sync;
 
  } 
 
  @Implementation 
  public static boolean getMasterSyncAutomatically() { 
    return masterSyncAutomatically;
  } 
 
 
  public static ContentProvider getProvider(Uri uri) {
    if (uri == null) {
      return null; 
    } else if (!ContentResolver.SCHEME_CONTENT.equals(uri.getScheme())) {
      return null; 
    } else { 
      return providers.get(uri.getAuthority());
    } 
  } 
 
  public static void registerProvider(String authority, ContentProvider provider) {
    providers.put(authority, provider);