本文整理汇总了Java中android.app.Activity.getContentResolver方法的典型用法代码示例。如果您正苦于以下问题:Java Activity.getContentResolver方法的具体用法?Java Activity.getContentResolver怎么用?Java Activity.getContentResolver使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.app.Activity
的用法示例。
在下文中一共展示了Activity.getContentResolver方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getBitmapSize
import android.app.Activity; //导入方法依赖的package包/类
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));
}
示例2: getAutoScreenBrightness
import android.app.Activity; //导入方法依赖的package包/类
/**
* 获取自动模式下的屏幕亮度
* @return value:0~255
*/
public static int getAutoScreenBrightness(Activity activity) {
float nowBrightnessValue = 0;
//获取自动调节下的亮度范围在 0~1 之间
ContentResolver resolver = activity.getContentResolver();
try {
//TODO:获取到的值与实际的亮度有差异,没有找到能够获得真正亮度值的方法,希望大佬能够告知。
nowBrightnessValue = Settings.System.getFloat(resolver, "screen_auto_brightness_adj");
Log.d(TAG, "getAutoScreenBrightness: " + nowBrightnessValue);
} catch (Exception e) {
e.printStackTrace();
}
//转换范围为 (0~255)
float fValue = nowBrightnessValue * 225.0f;
Log.d(TAG,"brightness: " + fValue);
return (int)fValue;
}
示例3: onSwitched
import android.app.Activity; //导入方法依赖的package包/类
@Override
public void onSwitched(boolean switched) {
final Activity activity = mActivity;
final ContentResolver resolver = activity.getContentResolver();
setAutobrightness(activity, resolver, switched);
// update setting and view
RangeSetting setting = (RangeSetting) mSetting;
setting.checked = switched;
setting.descr = switched ? activity.getString(R.string.txt_autobrightness_enabled) : null;
if (!switched) {
// refresh value
final int value = Settings.System.getInt(resolver, Settings.System.SCREEN_BRIGHTNESS, 0);
setting.value = getPercentValue(value);
}
setting.updateView();
}
示例4: loadImgThumbnail
import android.app.Activity; //导入方法依赖的package包/类
/**
* 获取图片缩略图 只有Android2.1以上版本支持
*
* @param imgName
* @param kind MediaStore.Images.Thumbnails.MICRO_KIND
* @return
*/
@SuppressWarnings("deprecation")
public static Bitmap loadImgThumbnail(Activity context, String imgName,
int kind) {
Bitmap bitmap = null;
String[] proj = {MediaStore.Images.Media._ID,
MediaStore.Images.Media.DISPLAY_NAME};
Cursor cursor = context.managedQuery(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI, proj,
MediaStore.Images.Media.DISPLAY_NAME + "='" + imgName + "'",
null, null);
if (cursor != null && cursor.getCount() > 0 && cursor.moveToFirst()) {
ContentResolver crThumb = context.getContentResolver();
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 1;
bitmap = MethodsCompat.getThumbnail(crThumb, cursor.getInt(0),
kind, options);
}
return bitmap;
}
示例5: initContentObserver
import android.app.Activity; //导入方法依赖的package包/类
static void initContentObserver(Activity activity) {
Uri contactsUri = ContactsContract.Contacts.CONTENT_URI;
ContentResolver contentResolver = activity.getContentResolver();
contentResolver.
registerContentObserver(
contactsUri,
true,
new ContactsObserver(new Handler(), activity));
}
示例6: initContentObserver
import android.app.Activity; //导入方法依赖的package包/类
static void initContentObserver(Activity activity) {
Uri externalImagesUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
Uri internalImagesUri = MediaStore.Images.Media.INTERNAL_CONTENT_URI;
Uri externalVideosUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
Uri internalVideosUri = MediaStore.Video.Media.INTERNAL_CONTENT_URI;
ContentResolver contentResolver = activity.getContentResolver();
contentResolver.
registerContentObserver(
externalImagesUri,
true,
new MediaObserver(new Handler(), activity));
contentResolver.
registerContentObserver(
internalImagesUri,
true,
new MediaObserver(new Handler(), activity));
contentResolver.
registerContentObserver(
externalVideosUri,
true,
new MediaObserver(new Handler(), activity));
contentResolver.
registerContentObserver(
internalVideosUri,
true,
new MediaObserver(new Handler(), activity));
}
示例7: Modi_WangYi_Mp3_UI_doing
import android.app.Activity; //导入方法依赖的package包/类
public static void Modi_WangYi_Mp3_UI_doing(Activity con, int requestCode, int resultCode, Intent in)
{
if (requestCode == requestcode && resultCode == Activity.RESULT_OK)
{
Uri uri = in.getData();
ContentResolver cr = con.getContentResolver();
try
{
Bitmap bmp = BitmapFactory.decodeStream(cr.openInputStream(uri));
File[] files = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/netease/cloudmusic/Ad/").listFiles();
if (files == null)
{
Toast.makeText(con, "没安装网易音乐或者是没有加载广告", Toast.LENGTH_LONG).show();
return;
}
Vector<String> c=new Vector<String>();
for (File f : files)
{
if (f.isDirectory())
{
File[] temp_files=f.listFiles();
if (temp_files == null) continue;
for (File inner_f : temp_files)
{
if (inner_f.isFile())
c.add(inner_f.getAbsolutePath());
}
}
if (f.isFile())
c.add(f.getAbsolutePath());
}
for (String s : c)
{
OutputStream ops=new FileOutputStream(s);
bmp.compress(Bitmap.CompressFormat.JPEG, 100, ops);
}
}
catch (FileNotFoundException e)
{
e.printStackTrace();
}
Toast.makeText(con, "替换完成", Toast.LENGTH_SHORT).show();
//finish();
}
}
示例8: GetISfromIntent
import android.app.Activity; //导入方法依赖的package包/类
public static InputStream GetISfromIntent(Intent u, Activity con)
{
ContentResolver cr = con.getContentResolver();
try
{
return cr.openInputStream(u.getData());
}
catch (FileNotFoundException e)
{
e.printStackTrace();
return null;
}
}
示例9: checkWriteCallLog
import android.app.Activity; //导入方法依赖的package包/类
/**
* 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;
}
示例10: getManualScreenBrightness
import android.app.Activity; //导入方法依赖的package包/类
/**
* 获取手动模式下的屏幕亮度
* @return value:0~255
*/
public static int getManualScreenBrightness(Activity activity) {
int nowBrightnessValue = 0;
ContentResolver resolver = activity.getContentResolver();
try {
nowBrightnessValue = Settings.System.getInt(resolver, Settings.System.SCREEN_BRIGHTNESS);
} catch (Exception e) {
e.printStackTrace();
}
return nowBrightnessValue;
}
示例11: Utils
import android.app.Activity; //导入方法依赖的package包/类
public Utils(Activity a) {
activity = a;
cr = a.getContentResolver();
options = PreferenceManager.getDefaultSharedPreferences(a);
outResolution = Integer.parseInt(options.getString(Options.PREF_RESOLUTION, "1024"));
outQuality = Integer.parseInt(options.getString(Options.PREF_QUALITY, "85"));
}
示例12: onAttach
import android.app.Activity; //导入方法依赖的package包/类
@Override
public void onAttach(final Activity activity) {
super.onAttach(activity);
this.activity = (AbstractBindServiceActivity) activity;
this.application = (WalletApplication) activity.getApplication();
this.config = application.getConfiguration();
this.wallet = application.getWallet();
this.contentResolver = activity.getContentResolver();
this.loaderManager = getLoaderManager();
this.fragmentManager = getFragmentManager();
}
示例13: onAttach
import android.app.Activity; //导入方法依赖的package包/类
@Override
public void onAttach(final Activity activity) {
super.onAttach(activity);
this.activity = (AbstractWalletActivity) activity;
this.application = (WalletApplication) activity.getApplication();
this.config = application.getConfiguration();
this.wallet = application.getWallet();
this.resolver = activity.getContentResolver();
this.loaderManager = getLoaderManager();
this.devicePolicyManager = (DevicePolicyManager) application.getSystemService(Context.DEVICE_POLICY_SERVICE);
}
示例14: onAttach
import android.app.Activity; //导入方法依赖的package包/类
@Override
public void onAttach(final Activity activity) {
super.onAttach(activity);
this.activity = activity;
final WalletApplication application = (WalletApplication) activity.getApplication();
this.wallet = application.getWallet();
this.contentResolver = activity.getContentResolver();
}
示例15: onAttach
import android.app.Activity; //导入方法依赖的package包/类
@Override
public void onAttach(final Activity activity) {
super.onAttach(activity);
this.activity = (AddressBookActivity) activity;
this.application = (WalletApplication) activity.getApplication();
this.config = application.getConfiguration();
this.wallet = application.getWallet();
this.clipboardManager = (ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE);
this.contentResolver = activity.getContentResolver();
}