android.app.Activity.getContentResolver()方法的使用及代码示例

x33g5p2x  于2022-01-15 转载在 其他  
字(12.9k)|赞(0)|评价(0)|浏览(151)

本文整理了Java中android.app.Activity.getContentResolver()方法的一些代码示例,展示了Activity.getContentResolver()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Activity.getContentResolver()方法的具体详情如下:
包路径:android.app.Activity
类名称:Activity
方法名:getContentResolver

Activity.getContentResolver介绍

暂无

代码示例

代码示例来源:origin: smuyyh/BookReader

/**
 * 关闭亮度自动调节
 *
 * @param activity
 */
public static void stopAutoBrightness(Activity activity) {
  Settings.System.putInt(activity.getContentResolver(),
      Settings.System.SCREEN_BRIGHTNESS_MODE,
      Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL);
}

代码示例来源:origin: smuyyh/BookReader

/**
 * 开启亮度自动调节
 *
 * @param activity
 */
public static void startAutoBrightness(Activity activity) {
  Settings.System.putInt(activity.getContentResolver(),
      Settings.System.SCREEN_BRIGHTNESS_MODE,
      Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC);
}

代码示例来源:origin: stackoverflow.com

public boolean contactExists(Activity _activity, String number) {
  if (number != null) {
    Uri lookupUri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(number));
    String[] mPhoneNumberProjection = { PhoneLookup._ID, PhoneLookup.NUMBER, PhoneLookup.DISPLAY_NAME };
    Cursor cur = _activity.getContentResolver().query(lookupUri, mPhoneNumberProjection, null, null, null);
    try {
      if (cur.moveToFirst()) {
        return true;
      }
    } finally {
      if (cur != null)
        cur.close();
    }
    return false;
  } else {
    return false;
  }
}// contactExists

代码示例来源:origin: jokermonn/permissions4m

/**
 * read calendar, {@link android.Manifest.permission#READ_CALENDAR}
 *
 * @param activity
 * @return true if success
 */
private static boolean checkReadCalendar(Activity activity) throws Exception {
  Cursor cursor = activity.getContentResolver().query(Uri.parse("content://com" +
      ".android.calendar/calendars"), null, null, null, null);
  if (cursor != null) {
    cursor.close();
    return true;
  } else {
    return false;
  }
}

代码示例来源:origin: jokermonn/permissions4m

/**
 * write or delete call log, {@link android.Manifest.permission#WRITE_CALL_LOG}
 *
 * @param activity
 * @return true if success
 */
private static boolean checkWriteCallLog(Activity activity) throws Exception {
  ContentResolver contentResolver = activity.getContentResolver();
  ContentValues content = new ContentValues();
  content.put(CallLog.Calls.TYPE, CallLog.Calls.INCOMING_TYPE);
  content.put(CallLog.Calls.NUMBER, TAG_NUMBER);
  content.put(CallLog.Calls.DATE, 20140808);
  content.put(CallLog.Calls.NEW, "0");
  contentResolver.insert(Uri.parse("content://call_log/calls"), content);
  contentResolver.delete(Uri.parse("content://call_log/calls"), "number = ?", new
      String[]{TAG_NUMBER});
  return true;
}

代码示例来源:origin: zhihu/Matisse

public static Point getBitmapSize(Uri uri, Activity activity) {
  ContentResolver resolver = activity.getContentResolver();
  Point imageSize = getBitmapBound(resolver, uri);
  int w = imageSize.x;
  int h = imageSize.y;
  if (PhotoMetadataUtils.shouldRotate(resolver, uri)) {
    w = imageSize.y;
    h = imageSize.x;
  }
  if (h == 0) return new Point(MAX_WIDTH, MAX_WIDTH);
  DisplayMetrics metrics = new DisplayMetrics();
  activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
  float screenWidth = (float) metrics.widthPixels;
  float screenHeight = (float) metrics.heightPixels;
  float widthScale = screenWidth / w;
  float heightScale = screenHeight / h;
  if (widthScale > heightScale) {
    return new Point((int) (w * widthScale), (int) (h * heightScale));
  }
  return new Point((int) (w * widthScale), (int) (h * heightScale));
}

代码示例来源:origin: crazycodeboy/TakePhoto

/**
 * 通过URI获取文件
 *
 * @param uri
 * @param activity
 * @return Author JPH
 * Date 2016/10/25
 */
public static File getFileWithUri(Uri uri, Activity activity) {
  String picturePath = null;
  String scheme = uri.getScheme();
  if (ContentResolver.SCHEME_CONTENT.equals(scheme)) {
    String[] filePathColumn = {MediaStore.Images.Media.DATA};
    Cursor cursor = activity.getContentResolver().query(uri, filePathColumn, null, null, null);//从系统表中查询指定Uri对应的照片
    cursor.moveToFirst();
    int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
    if (columnIndex >= 0) {
      picturePath = cursor.getString(columnIndex);  //获取照片路径
    } else if (TextUtils.equals(uri.getAuthority(), TConstant.getFileProviderName(activity))) {
      picturePath = parseOwnUri(activity, uri);
    }
    cursor.close();
  } else if (ContentResolver.SCHEME_FILE.equals(scheme)) {
    picturePath = uri.getPath();
  }
  return TextUtils.isEmpty(picturePath) ? null : new File(picturePath);
}

代码示例来源:origin: jeasonlzy/ImagePicker

/**
 * 获取我们需要的整理过旋转角度的Uri
 * @param activity  上下文环境
 * @param path      路径
 * @return          正常的Uri
 */
public static Uri getRotatedUri(Activity activity, String path){
  int degree = BitmapUtil.getBitmapDegree(path);
  if (degree != 0){
    Bitmap bitmap = BitmapFactory.decodeFile(path);
    Bitmap newBitmap = BitmapUtil.rotateBitmapByDegree(bitmap,degree);
    return Uri.parse(MediaStore.Images.Media.insertImage(activity.getContentResolver(),newBitmap,null,null));
  }else{
    return Uri.fromFile(new File(path));
  }
}

代码示例来源:origin: crazycodeboy/TakePhoto

/**
   * 通过从文件中得到的URI获取文件的路径
   *
   * @param uri
   * @param activity
   * @return Author JPH
   * Date 2016/6/6 0006 20:01
   */
  public static String getFilePathWithDocumentsUri(Uri uri, Activity activity) throws TException {
    if (uri == null) {
      Log.e(TAG, "uri is null,activity may have been recovered?");
      return null;
    }
    if (ContentResolver.SCHEME_CONTENT.equals(uri.getScheme()) && uri.getPath().contains("document")) {
      File tempFile = TImageFiles.getTempFile(activity, uri);
      try {
        TImageFiles.inputStreamToFile(activity.getContentResolver().openInputStream(uri), tempFile);
        return tempFile.getPath();
      } catch (FileNotFoundException e) {
        e.printStackTrace();
        throw new TException(TExceptionType.TYPE_NO_FIND);
      }
    } else {
      return getFilePathWithUri(uri, activity);
    }
  }
}

代码示例来源:origin: smuyyh/BookReader

/**
 * 判断是否开启了自动亮度调节
 *
 * @param activity
 * @return
 */
public static boolean isAutoBrightness(Activity activity) {
  boolean isAutoAdjustBright = false;
  try {
    isAutoAdjustBright = Settings.System.getInt(
        activity.getContentResolver(),
        Settings.System.SCREEN_BRIGHTNESS_MODE) == Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC;
  } catch (Settings.SettingNotFoundException e) {
    e.printStackTrace();
  }
  return isAutoAdjustBright;
}

代码示例来源:origin: crazycodeboy/TakePhoto

/**
 * To find out the extension of required object in given uri
 * Solution by http://stackoverflow.com/a/36514823/1171484
 */
public static String getMimeType(Activity context, Uri uri) {
  String extension;
  //Check uri format to avoid null
  if (ContentResolver.SCHEME_CONTENT.equals(uri.getScheme())) {
    //If scheme is a content
    extension = MimeTypeMap.getSingleton().getExtensionFromMimeType(context.getContentResolver().getType(uri));
    if (TextUtils.isEmpty(extension)) {
      extension = MimeTypeMap.getFileExtensionFromUrl(Uri.fromFile(new File(uri.getPath())).toString());
    }
  } else {
    //If scheme is a File
    //This will replace white spaces with %20 and also other special characters. This will avoid returning null values on file
    // name with spaces and special characters.
    extension = MimeTypeMap.getFileExtensionFromUrl(Uri.fromFile(new File(uri.getPath())).toString());
    if (TextUtils.isEmpty(extension)) {
      extension = MimeTypeMap.getSingleton().getExtensionFromMimeType(context.getContentResolver().getType(uri));
    }
  }
  if (TextUtils.isEmpty(extension)) {
    extension = getMimeTypeByFileName(TUriParse.getFileWithUri(uri, context).getName());
  }
  return extension;
}

代码示例来源:origin: robolectric/robolectric

@Test
public void shouldReturnSameContentResolverEveryTime() throws Exception {
 Activity activity = Robolectric.setupActivity(Activity.class);
 assertThat(activity.getContentResolver()).isSameAs(activity.getContentResolver());
 assertThat(activity.getContentResolver()).isSameAs(Robolectric.setupActivity(Activity.class).getContentResolver());
}

代码示例来源:origin: udacity/ud851-Sunshine

@Override
  public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
    Activity activity = getActivity();

    if (key.equals(getString(R.string.pref_location_key))) {
      // we've changed the location
      // Wipe out any potential PlacePicker latlng values so that we can use this text entry.
      SunshinePreferences.resetLocationCoordinates(activity);
    } else if (key.equals(getString(R.string.pref_units_key))) {
      // units have changed. update lists of weather entries accordingly
      activity.getContentResolver().notifyChange(WeatherContract.WeatherEntry.CONTENT_URI, null);
    }
    Preference preference = findPreference(key);
    if (null != preference) {
      if (!(preference instanceof CheckBoxPreference)) {
        setPreferenceSummary(preference, sharedPreferences.getString(key, ""));
      }
    }
  }
}

代码示例来源:origin: udacity/ud851-Sunshine

@Override
  public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
    Activity activity = getActivity();

    if (key.equals(getString(R.string.pref_location_key))) {
      // we've changed the location
      // Wipe out any potential PlacePicker latlng values so that we can use this text entry.
      SunshinePreferences.resetLocationCoordinates(activity);
    } else if (key.equals(getString(R.string.pref_units_key))) {
      // units have changed. update lists of weather entries accordingly
      activity.getContentResolver().notifyChange(WeatherContract.WeatherEntry.CONTENT_URI, null);
    }
    Preference preference = findPreference(key);
    if (null != preference) {
      if (!(preference instanceof CheckBoxPreference)) {
        setPreferenceSummary(preference, sharedPreferences.getString(key, ""));
      }
    }
  }
}

代码示例来源:origin: udacity/ud851-Sunshine

@Override
  public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
    Activity activity = getActivity();

    if (key.equals(getString(R.string.pref_location_key))) {
      // we've changed the location
      // Wipe out any potential PlacePicker latlng values so that we can use this text entry.
      SunshinePreferences.resetLocationCoordinates(activity);
    } else if (key.equals(getString(R.string.pref_units_key))) {
      // units have changed. update lists of weather entries accordingly
      activity.getContentResolver().notifyChange(WeatherContract.WeatherEntry.CONTENT_URI, null);
    }
    Preference preference = findPreference(key);
    if (null != preference) {
      if (!(preference instanceof CheckBoxPreference)) {
        setPreferenceSummary(preference, sharedPreferences.getString(key, ""));
      }
    }
  }
}

代码示例来源:origin: udacity/ud851-Sunshine

@Override
  public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
    Activity activity = getActivity();

    if (key.equals(getString(R.string.pref_location_key))) {
      // we've changed the location
      // Wipe out any potential PlacePicker latlng values so that we can use this text entry.
      SunshinePreferences.resetLocationCoordinates(activity);
    } else if (key.equals(getString(R.string.pref_units_key))) {
      // units have changed. update lists of weather entries accordingly
      activity.getContentResolver().notifyChange(WeatherContract.WeatherEntry.CONTENT_URI, null);
    }
    Preference preference = findPreference(key);
    if (null != preference) {
      if (!(preference instanceof CheckBoxPreference)) {
        setPreferenceSummary(preference, sharedPreferences.getString(key, ""));
      }
    }
  }
}

代码示例来源:origin: udacity/ud851-Sunshine

@Override
  public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
    Activity activity = getActivity();

    if (key.equals(getString(R.string.pref_location_key))) {
      // we've changed the location
      // Wipe out any potential PlacePicker latlng values so that we can use this text entry.
      SunshinePreferences.resetLocationCoordinates(activity);
    } else if (key.equals(getString(R.string.pref_units_key))) {
      // units have changed. update lists of weather entries accordingly
      activity.getContentResolver().notifyChange(WeatherContract.WeatherEntry.CONTENT_URI, null);
    }
    Preference preference = findPreference(key);
    if (null != preference) {
      if (!(preference instanceof CheckBoxPreference)) {
        setPreferenceSummary(preference, sharedPreferences.getString(key, ""));
      }
    }
  }
}

代码示例来源:origin: udacity/ud851-Sunshine

@Override
  public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
    Activity activity = getActivity();

    if (key.equals(getString(R.string.pref_location_key))) {
      // we've changed the location
      // Wipe out any potential PlacePicker latlng values so that we can use this text entry.
      SunshinePreferences.resetLocationCoordinates(activity);
    } else if (key.equals(getString(R.string.pref_units_key))) {
      // units have changed. update lists of weather entries accordingly
      activity.getContentResolver().notifyChange(WeatherContract.WeatherEntry.CONTENT_URI, null);
    }
    Preference preference = findPreference(key);
    if (null != preference) {
      if (!(preference instanceof CheckBoxPreference)) {
        setPreferenceSummary(preference, sharedPreferences.getString(key, ""));
      }
    }
  }
}

代码示例来源:origin: udacity/ud851-Sunshine

@Override
  public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
    Activity activity = getActivity();

    if (key.equals(getString(R.string.pref_location_key))) {
      // we've changed the location
      // Wipe out any potential PlacePicker latlng values so that we can use this text entry.
      SunshinePreferences.resetLocationCoordinates(activity);
    } else if (key.equals(getString(R.string.pref_units_key))) {
      // units have changed. update lists of weather entries accordingly
      activity.getContentResolver().notifyChange(WeatherContract.WeatherEntry.CONTENT_URI, null);
    }
    Preference preference = findPreference(key);
    if (null != preference) {
      if (!(preference instanceof CheckBoxPreference)) {
        setPreferenceSummary(preference, sharedPreferences.getString(key, ""));
      }
    }
  }
}

代码示例来源:origin: facebook/facebook-android-sdk

@Before
public void setup() {
 mMockActivity = mock(Activity.class);
 mMockContentResolver = mock(ContentResolver.class);
 when(mMockActivity.getContentResolver()).thenReturn(mMockContentResolver);
 FacebookSdk.setApplicationId("200");
 FacebookSdk.setAutoLogAppEventsEnabled(false);
 FacebookSdk.sdkInitialize(RuntimeEnvironment.application);
 PowerMockito.mockStatic(FacebookSignatureValidator.class);
}

相关文章

微信公众号

最新文章

更多

Activity类方法