Example usage for android.app Activity getContentResolver

List of usage examples for android.app Activity getContentResolver

Introduction

In this page you can find the example usage for android.app Activity getContentResolver.

Prototype

@Override
    public ContentResolver getContentResolver() 

Source Link

Usage

From source file:disono.webmons.com.utilities.helpers.WBFile.java

/**
 * Get the real path from URI/*  w  w  w .j  a v a  2 s .  c  o  m*/
 *
 * @param activity
 * @param uri
 * @return
 */
public static String getRealPathFromURI(Activity activity, Uri uri) {
    Cursor cursor = activity.getContentResolver().query(uri, null, null, null, null);
    assert cursor != null;
    cursor.moveToFirst();
    int idx = cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA);
    return cursor.getString(idx);
}

From source file:Main.java

public static boolean isAutoBrightness(Activity activity) {
    boolean isAuto = false;
    try {/*from w ww  . j  av  a2 s . co  m*/
        isAuto = Settings.System.getInt(activity.getContentResolver(),
                Settings.System.SCREEN_BRIGHTNESS_MODE) == Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC;
    } catch (Settings.SettingNotFoundException e) {
        e.printStackTrace();
    }
    return isAuto;
}

From source file:Main.java

public static String getRealImagePath(Activity activity, Uri uriPath) {
    String[] proj = { MediaStore.Images.Media.DATA };
    Cursor cursor = activity.getContentResolver().query(uriPath, proj, null, null, null);
    int index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
    cursor.moveToFirst();/*from  w ww .  j av  a2s . c o m*/
    String path = cursor.getString(index);
    // path = path.substring(5);
    return path;
}

From source file:Main.java

public static int getScreenBrightness(Activity activity) {
    int brightnessValue = 0;
    try {//from   www. ja v  a 2  s . c o m
        brightnessValue = Settings.System.getInt(activity.getContentResolver(),
                Settings.System.SCREEN_BRIGHTNESS);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return brightnessValue;
}

From source file:Main.java

public static void addToCalendar(Activity context, Long beginTime, String title) {
    ContentResolver cr = context.getContentResolver();

    Uri.Builder builder = Uri.parse("content://com.android.calendar/instances/when").buildUpon();
    Long time = new Date(beginTime).getTime();
    ContentUris.appendId(builder, time - 10 * 60 * 1000);
    ContentUris.appendId(builder, time + 10 * 60 * 1000);

    String[] projection = new String[] { "title", "begin" };
    Cursor cursor = cr.query(builder.build(), projection, null, null, null);

    boolean exists = false;
    if (cursor != null) {
        while (cursor.moveToNext()) {
            if ((time == cursor.getLong(1)) && title.equals(cursor.getString(0))) {
                exists = true;/*from  w ww.  j av  a  2  s.  c  om*/
            }
        }
    }

    if (!exists) {
        Intent intent = new Intent(Intent.ACTION_EDIT);
        intent.setType("vnd.android.cursor.item/event");
        intent.putExtra("beginTime", time);
        intent.putExtra("allDay", false);
        intent.putExtra("endTime", time + 60 * 60 * 1000);
        intent.putExtra("title", title);
        context.startActivity(intent);
    } else {
        Toast.makeText(context, "Event already exist!", Toast.LENGTH_LONG).show();
    }
}

From source file:Main.java

public static void saveBrightness(Activity activity, int brightness) {
    Uri uri = Settings.System.getUriFor("screen_brightness");
    ContentResolver resolver = activity.getContentResolver();
    Settings.System.putInt(resolver, "screen_brightness", brightness);
    resolver.notifyChange(uri, null);/* w  w w.j a  v  a 2  s  .c  om*/
}

From source file:edu.stanford.mobisocial.dungbeetle.ui.fragments.ObjCommentsFragment.java

/**
 * The parametrization here is absolutely not final.
 *///from ww  w  . jav a 2s. c om
public static View getViewForObjComments(Activity activity, Uri feedUri, JSONObject obj) {

    Cursor c = activity.getContentResolver().query(feedUri, null, DbObjects.getFeedObjectClause(null), null,
            DbObject._ID + " DESC LIMIT 2");
    try {
        SpinnerAdapter adapter = new ObjectListCursorAdapter(activity, c);

        Gallery gallery = new Gallery(activity);
        gallery.setLayoutParams(CommonLayouts.FULL_SCREEN);
        gallery.setAdapter(adapter);

        return gallery;
    } finally {
        c.close();
    }
}

From source file:Main.java

public static boolean isExistShortcut(Activity context, String authorities) {
    boolean isInstallShortcut = false;
    final ContentResolver cr = context.getContentResolver();

    final Uri CONTENT_URI = Uri.parse("content://" + authorities + "/favorites?notify=true");
    Cursor c = cr.query(CONTENT_URI, new String[] { "iconPackage" }, "iconPackage=?",
            new String[] { context.getApplication().getPackageName() }, null);
    if (c != null) {
        if (c.getCount() > 0) {
            isInstallShortcut = true;/*from   w  ww.  j  av a 2 s. c o  m*/
        }
        c.close();
    }
    return isInstallShortcut;
}

From source file:Main.java

public static int getScreenBrightness(Activity activity) {
    int screenBrightness = 0;
    try {//www . j  a  v  a  2s. co m
        screenBrightness = android.provider.Settings.System.getInt(activity.getContentResolver(),
                android.provider.Settings.System.SCREEN_BRIGHTNESS);
    } catch (Exception ex) {
    }
    return screenBrightness;
}

From source file:Main.java

public static void saveBrightness(Activity activity, int brightness) {
    Uri uri = android.provider.Settings.System.getUriFor("screen_brightness");
    ContentResolver resolver = activity.getContentResolver();
    android.provider.Settings.System.putInt(resolver, "screen_brightness", brightness);
    resolver.notifyChange(uri, null);/*from  w  ww  . ja  v  a  2s . c o m*/
}