Example usage for android.content Context getContentResolver

List of usage examples for android.content Context getContentResolver

Introduction

In this page you can find the example usage for android.content Context getContentResolver.

Prototype

public abstract ContentResolver getContentResolver();

Source Link

Document

Return a ContentResolver instance for your application's package.

Usage

From source file:Main.java

public static int getBaiduHalfDownloadValue(Context context) {
    synchronized (HALF_DOWNLOAD_VALUE) {
        return System.getInt(context.getContentResolver(), HALF_DOWNLOAD_VALUE, HALF_VALUE);
    }//w  w  w  .  j  av  a2s.  c  o m
}

From source file:Main.java

/**
 * Deletes the calendar TUM_Campus_APP from google calendar
 * @param c Context/*from www. j a v a 2s. com*/
 * @return Number of rows deleted
 */
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
public static int deleteCalendar(Context c) {
    Uri uri = CalendarContract.Calendars.CONTENT_URI;
    return c.getContentResolver().delete(uri, " account_name = '" + ACCOUNT_NAME + "'", null);
}

From source file:Main.java

public static InputStream getISFromURI(Context context, Uri contentURI) {
    ContentResolver res = context.getContentResolver();
    Uri uri = Uri.parse(contentURI.toString());
    InputStream is = null;/*from w  ww .j a va  2s.  c  o m*/
    try {
        is = res.openInputStream(uri);
    } catch (FileNotFoundException e) {
        jlog(e);
    }

    return is;
}

From source file:Main.java

/**
 * Get Image orientation from uri/* w ww  . jav a 2  s  .  co  m*/
 *
 * @param context  Context of image
 * @param photoUri Uri of image
 * @return
 */
public static int getOrientation(Context context, Uri photoUri) {
    Cursor cursor = context.getContentResolver().query(photoUri,
            new String[] { MediaStore.Images.ImageColumns.ORIENTATION }, null, null, null);

    try {
        if (cursor.moveToFirst()) {
            if (cursor.getInt(0) == ORIENTATION_270)
                return ExifInterface.ORIENTATION_ROTATE_270;
            else if (cursor.getInt(0) == ORIENTATION_180)
                return ExifInterface.ORIENTATION_ROTATE_180;
            else if (cursor.getInt(0) == ORIENTATION_90)
                return ExifInterface.ORIENTATION_ROTATE_90;
        }
    } finally {
        cursor.close();
    }
    return -1;
}

From source file:Main.java

public static String readTextFromUri(Context context, Uri uri) throws IOException {
    InputStream inputStream = context.getContentResolver().openInputStream(uri);
    BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
    StringBuilder stringBuilder = new StringBuilder();
    String line;//from   w  ww . ja  va 2 s  .  c o  m
    while ((line = reader.readLine()) != null) {
        stringBuilder.append(line);
    }
    inputStream.close();
    reader.close();
    return stringBuilder.toString();
}

From source file:Main.java

public static void setBaiDuHalfDownloadValue(Context context, int value) {
    synchronized (HALF_DOWNLOAD_VALUE) {
        System.putInt(context.getContentResolver(), HALF_DOWNLOAD_VALUE, value);
    }//from   w w w  .  j a  va2 s.com
}

From source file:Main.java

public static void deleteSinglePicture(Context ctx, String path) {
    String params[] = new String[] { path };
    ctx.getContentResolver().delete(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
            MediaStore.Images.Media.DATA + " LIKE ?", params);
    File file = new File(path);
    File pFile = file.getParentFile();
    if (pFile != null && pFile.isDirectory()) {
        File files[] = pFile.listFiles();
        if (files == null || files.length == 0) {
            pFile.delete();/*from   w  ww .  j av  a2  s . c  o m*/
        }
    }
}

From source file:Main.java

public static void writeTextToUri(Context context, Uri uri, String string) throws IOException {
    OutputStream outputStream = context.getContentResolver().openOutputStream(uri);
    outputStream.write(string.getBytes());
    outputStream.close();/* w w  w. j av  a2  s. c o  m*/
}

From source file:Main.java

public static boolean isImmediatelyDestroyActivities(Context context) {
    boolean flag = false;
    if (android.provider.Settings.System.getInt(context.getContentResolver(), "always_finish_activities",
            0) != 0)// w  w w.  j a  v a 2s . c om
        flag = true;
    return flag;
}

From source file:Main.java

public static String getAbsoluteImagePath(Context context, Uri uri) {
    String imagePath = "";
    Cursor cursor = context.getContentResolver().query(uri, null, null, null, null);

    if (cursor != null) {
        int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
        if (cursor.getCount() > 0 && cursor.moveToFirst()) {
            imagePath = cursor.getString(column_index);
        }//from w w w.  jav a 2  s  .co m
    }

    return imagePath;
}