本文整理匯總了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();
}