Tabnine Logo
Context.getContentResolver
Code IndexAdd Tabnine to your IDE (free)

How to use
getContentResolver
method
in
android.content.Context

Best Java code snippets using android.content.Context.getContentResolver (Showing top 20 results out of 7,812)

Refine searchRefine arrow

  • Cursor.moveToFirst
  • Cursor.getString
  • Cursor.close
  • Cursor.getColumnIndex
  • Cursor.moveToNext
origin: stackoverflow.com

 public String getRealPathFromURI(Context context, Uri contentUri) {
 Cursor cursor = null;
 try { 
  String[] proj = { MediaStore.Images.Media.DATA };
  cursor = context.getContentResolver().query(contentUri,  proj, null, null, null);
  int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
  cursor.moveToFirst();
  return cursor.getString(column_index);
 } finally {
  if (cursor != null) {
   cursor.close();
  }
 }
}
origin: square/picasso

@Override
protected int getExifOrientation(Uri uri) {
 Cursor cursor = null;
 try {
  ContentResolver contentResolver = context.getContentResolver();
  cursor = contentResolver.query(uri, CONTENT_ORIENTATION, null, null, null);
  if (cursor == null || !cursor.moveToFirst()) {
   return 0;
  }
  return cursor.getInt(0);
 } catch (RuntimeException ignored) {
  // If the orientation column doesn't exist, assume no rotation.
  return 0;
 } finally {
  if (cursor != null) {
   cursor.close();
  }
 }
}
origin: stackoverflow.com

 public static int getOrientation(Context context, Uri photoUri) {
  /* it's on the external media. */
  Cursor cursor = context.getContentResolver().query(photoUri,
      new String[] { MediaStore.Images.ImageColumns.ORIENTATION }, null, null, null);

  if (cursor.getCount() != 1) {
    return -1;
  }

  cursor.moveToFirst();
  return cursor.getInt(0);
}
origin: stackoverflow.com

 public static int getContactIDFromNumber(String contactNumber,Context context)
{
  contactNumber = Uri.encode(contactNumber);
  int phoneContactID = new Random().nextInt();
  Cursor contactLookupCursor = context.getContentResolver().query(Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI,contactNumber),new String[] {PhoneLookup.DISPLAY_NAME, PhoneLookup._ID}, null, null, null);
    while(contactLookupCursor.moveToNext()){
      phoneContactID = contactLookupCursor.getInt(contactLookupCursor.getColumnIndexOrThrow(PhoneLookup._ID));
      }
    contactLookupCursor.close();

  return phoneContactID;
}
origin: commonsguy/cw-omnibus

void bindModel(Cursor row) {
 title.setText(row.getString(row.getColumnIndex(MediaStore.Video.Media.TITLE)));
 int uriColumn=row.getColumnIndex(MediaStore.Video.Media.DATA);
 int mimeTypeColumn=
   row.getColumnIndex(MediaStore.Video.Media.MIME_TYPE);
 int videoId=row.getInt(row.getColumnIndex(MediaStore.Video.Media._ID));
 videoUri=row.getString(uriColumn);
 videoMimeType=row.getString(mimeTypeColumn);
  ContentResolver cr=thumbnail.getContext().getContentResolver();
  BitmapFactory.Options options=new BitmapFactory.Options();
origin: stackoverflow.com

public static Uri getImageContentUri(Context context, File imageFile) {
   String filePath = imageFile.getAbsolutePath();
   Cursor cursor = context.getContentResolver().query(
       MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
       new String[] { MediaStore.Images.Media._ID },
       MediaStore.Images.Media.DATA + "=? ",
       new String[] { filePath }, null);
   if (cursor != null && cursor.moveToFirst()) {
     int id = cursor.getInt(cursor
         .getColumnIndex(MediaStore.MediaColumns._ID));
     Uri baseUri = Uri.parse("content://media/external/images/media");
     return Uri.withAppendedPath(baseUri, "" + id);
   } else {
     if (imageFile.exists()) {
       ContentValues values = new ContentValues();
       values.put(MediaStore.Images.Media.DATA, filePath);
       return context.getContentResolver().insert(
           MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
     } else {
       return null;
     }
   }
 }
origin: naman14/Timber

public static final long[] getSongListForArtist(final Context context, final long id) {
  final String[] projection = new String[]{
      BaseColumns._ID
  };
  final String selection = MediaStore.Audio.AudioColumns.ARTIST_ID + "=" + id + " AND "
      + MediaStore.Audio.AudioColumns.IS_MUSIC + "=1";
  Cursor cursor = context.getContentResolver().query(
      MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, projection, selection, null,
      MediaStore.Audio.AudioColumns.ALBUM_KEY + "," + MediaStore.Audio.AudioColumns.TRACK);
  if (cursor != null) {
    final long[] mList = SongLoader.getSongListForCursor(cursor);
    cursor.close();
    cursor = null;
    return mList;
  }
  return sEmptyList;
}
origin: mayubao/KuaiChuan

Cursor cursor = context.getContentResolver().query(fileUri, projection, selection, null, sortOrder);
if(cursor != null){
  while (cursor.moveToNext()){
    try{
      String data = cursor.getString(0);
      FileInfo fileInfo = new FileInfo();
      fileInfo.setFilePath(data);
origin: ACRA/acra

@NonNull
public static String getFileNameFromUri(@NonNull Context context, @NonNull Uri uri) throws FileNotFoundException {
  try (Cursor cursor = context.getContentResolver().query(uri, new String[]{OpenableColumns.DISPLAY_NAME}, null, null, null)) {
    if (cursor != null && cursor.moveToFirst()) {
      return cursor.getString(cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME));
    }
  }
  throw new FileNotFoundException("Could not resolve filename of " + uri);
}
origin: cats-oss/android-gpuimage

  @Override
  protected int getImageOrientation() throws IOException {
    Cursor cursor = context.getContentResolver().query(uri,
        new String[]{MediaStore.Images.ImageColumns.ORIENTATION}, null, null, null);
    if (cursor == null || cursor.getCount() != 1) {
      return 0;
    }
    cursor.moveToFirst();
    int orientation = cursor.getInt(0);
    cursor.close();
    return orientation;
  }
}
origin: naman14/Timber

public static final long[] getSongListForAlbum(final Context context, final long id) {
  final String[] projection = new String[]{
      BaseColumns._ID
  };
  final String selection = MediaStore.Audio.AudioColumns.ALBUM_ID + "=" + id + " AND " + MediaStore.Audio.AudioColumns.IS_MUSIC
      + "=1";
  Cursor cursor = context.getContentResolver().query(
      MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, projection, selection, null,
      MediaStore.Audio.AudioColumns.TRACK + ", " + MediaStore.Audio.Media.DEFAULT_SORT_ORDER);
  if (cursor != null) {
    final long[] mList = SongLoader.getSongListForCursor(cursor);
    cursor.close();
    cursor = null;
    return mList;
  }
  return sEmptyList;
}
origin: stackoverflow.com

 public static String getPath(Context context, Uri uri) throws URISyntaxException {
  if ("content".equalsIgnoreCase(uri.getScheme())) {
    String[] projection = { "_data" };
    Cursor cursor = null;

    try {
      cursor = context.getContentResolver().query(uri, projection, null, null, null);
      int column_index = cursor.getColumnIndexOrThrow("_data");
      if (cursor.moveToFirst()) {
        return cursor.getString(column_index);
      }
    } catch (Exception e) {
      // Eat it
    }
  }
  else if ("file".equalsIgnoreCase(uri.getScheme())) {
    return uri.getPath();
  }

  return null;
}
origin: stackoverflow.com

 public boolean contactExists(Context context, String number) {
/// number is the phone number
Uri lookupUri = Uri.withAppendedPath(
PhoneLookup.CONTENT_FILTER_URI, 
Uri.encode(number));
String[] mPhoneNumberProjection = { PhoneLookup._ID, PhoneLookup.NUMBER, PhoneLookup.DISPLAY_NAME };
Cursor cur = context.getContentResolver().query(lookupUri,mPhoneNumberProjection, null, null, null);
try {
  if (cur.moveToFirst()) {
   return true;
}
} finally {
if (cur != null)
  cur.close();
}
return false;
}
origin: naman14/Timber

public static Song getSongFromPath(String songPath, Context context) {
  ContentResolver cr = context.getContentResolver();
  Uri uri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
  String selection = MediaStore.Audio.Media.DATA;
  String[] selectionArgs = {songPath};
  String[] projection = new String[]{"_id", "title", "artist", "album", "duration", "track", "artist_id", "album_id"};
  String sortOrder = MediaStore.Audio.Media.TITLE + " ASC";
  Cursor cursor = cr.query(uri, projection, selection + "=?", selectionArgs, sortOrder);
  if (cursor != null && cursor.getCount() > 0) {
    Song song = getSongForCursor(cursor);
    cursor.close();
    return song;
  }
  else return new Song();
}
origin: naman14/Timber

private String getValueForDownloadedFile(Context context, Uri uri, String column) {
  Cursor cursor = null;
  final String[] projection = {
      column
  };
  try {
    cursor = context.getContentResolver().query(uri, projection, null, null, null);
    if (cursor != null && cursor.moveToFirst()) {
      return cursor.getString(0);
    }
  } finally {
    if (cursor != null) {
      cursor.close();
    }
  }
  return null;
}
origin: naman14/Timber

public static final int getSongCountForPlaylist(final Context context, final long playlistId) {
  Cursor c = context.getContentResolver().query(
      MediaStore.Audio.Playlists.Members.getContentUri("external", playlistId),
      new String[]{BaseColumns._ID}, MUSIC_ONLY_SELECTION, null, null);
  if (c != null) {
    int count = 0;
    if (c.moveToFirst()) {
      count = c.getCount();
    }
    c.close();
    c = null;
    return count;
  }
  return 0;
}
origin: aa112901/remusic

private String getValueForDownloadedFile(Context context, Uri uri, String column) {
  Cursor cursor = null;
  final String[] projection = {
      column
  };
  try {
    cursor = context.getContentResolver().query(uri, projection, null, null, null);
    if (cursor != null && cursor.moveToFirst()) {
      return cursor.getString(0);
    }
  } finally {
    if (cursor != null) {
      cursor.close();
    }
  }
  return null;
}
origin: naman14/Timber

public static final int getSongCountForAlbumInt(final Context context, final long id) {
  int songCount = 0;
  if (id == -1) {
    return songCount;
  }
  Uri uri = ContentUris.withAppendedId(MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI, id);
  Cursor cursor = context.getContentResolver().query(uri,
      new String[]{MediaStore.Audio.AlbumColumns.NUMBER_OF_SONGS}, null, null, null);
  if (cursor != null) {
    cursor.moveToFirst();
    if (!cursor.isAfterLast()) {
      if (!cursor.isNull(0)) {
        songCount = cursor.getInt(0);
      }
    }
    cursor.close();
    cursor = null;
  }
  return songCount;
}
origin: Justson/AgentWeb

static String getDataColumn(Context context, Uri uri, String selection, String[] selectionArgs) {
  Cursor cursor = null;
  String[] projection = {MediaStore.Images.Media.DATA};
  try {
    cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs, null);
    if (cursor != null && cursor.moveToFirst()) {
      int index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
      return cursor.getString(index);
    }
  } finally {
    if (cursor != null) {
      cursor.close();
    }
  }
  return null;
}
origin: aa112901/remusic

public static final int getSongCountForAlbumInt(final Context context, final long id) {
  int songCount = 0;
  if (id == -1) {
    return songCount;
  }
  Uri uri = ContentUris.withAppendedId(MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI, id);
  Cursor cursor = context.getContentResolver().query(uri,
      new String[]{MediaStore.Audio.AlbumColumns.NUMBER_OF_SONGS}, null, null, null);
  if (cursor != null) {
    cursor.moveToFirst();
    if (!cursor.isAfterLast()) {
      if (!cursor.isNull(0)) {
        songCount = cursor.getInt(0);
      }
    }
    cursor.close();
    cursor = null;
  }
  return songCount;
}
android.contentContextgetContentResolver

Popular methods of Context

  • getPackageName
  • getResources
  • getSystemService
  • obtainStyledAttributes
  • getApplicationContext
  • getString
  • getPackageManager
  • startActivity
  • getSharedPreferences
  • getAssets
  • getTheme
  • getCacheDir
  • getTheme,
  • getCacheDir,
  • startService,
  • sendBroadcast,
  • getFilesDir,
  • registerReceiver,
  • getApplicationInfo,
  • unregisterReceiver,
  • getExternalCacheDir

Popular in Java

  • Start an intent from android
  • getApplicationContext (Context)
  • orElseThrow (Optional)
    Return the contained value, if present, otherwise throw an exception to be created by the provided s
  • ObjectMapper (com.fasterxml.jackson.databind)
    ObjectMapper provides functionality for reading and writing JSON, either to and from basic POJOs (Pl
  • ByteBuffer (java.nio)
    A buffer for bytes. A byte buffer can be created in either one of the following ways: * #allocate
  • Hashtable (java.util)
    A plug-in replacement for JDK1.5 java.util.Hashtable. This version is based on org.cliffc.high_scale
  • JComboBox (javax.swing)
  • StringUtils (org.apache.commons.lang)
    Operations on java.lang.String that arenull safe. * IsEmpty/IsBlank - checks if a String contains
  • Runner (org.openjdk.jmh.runner)
  • CodeWhisperer alternatives
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now