当前位置:  编程技术>移动开发
本页文章导读:
    ▪解决photo 过大内存溢出有关问题        解决photo 过大内存溢出问题 { Uri thumbUri = ContentUris.withAppendedId(PHOTO_CONTENT_URI, image); ParcelFileDescriptor pfdInput; try { BitmapFactory.Options options = new BitmapFactory.Options(); options.inDither .........
    ▪ [转]应用 NSDate,NSCalendar, NSDateComponents 获得时间之差总结        [转]使用 NSDate,NSCalendar, NSDateComponents 获得时间之差总结 原文: http://blog.csdn.net/JHorn/archive/2009/09/27/4602491.aspx方法一NSDate* toDate1 = [ [ NSDate alloc] initWithString:@"2520-9-26 17:10:00 +0600" ]; NSTimeInterv.........
    ▪ 治理联系人       管理联系人 通过Android系统提供的接口,可以很方便的管理联系人信息。添加添加联系人1.6上的代码 String peopleName = "name"; ContentValues personValues = new ContentValues(); // name personValues.put(Contacts.Peo.........

[1]解决photo 过大内存溢出有关问题
    来源: 互联网  发布时间: 2014-02-18
解决photo 过大内存溢出问题
{
				Uri thumbUri = ContentUris.withAppendedId(PHOTO_CONTENT_URI,
						image);
				ParcelFileDescriptor pfdInput;

			try {
					BitmapFactory.Options options = new BitmapFactory.Options();
					options.inDither = false;
					options.inPreferredConfig = Bitmap.Config.ARGB_8888;
					options.inSampleSize = 10;
					pfdInput = getContentResolver().openFileDescriptor(
							thumbUri, "r");
					bitmap = BitmapFactory.decodeFileDescriptor(pfdInput
							.getFileDescriptor(), null, options);
					pfdInput.close();
				} catch (FileNotFoundException ex) {
					Log.e(Tag, "couldn't open thumbnail " + thumbUri + "; "
							+ ex);
				} catch (IOException ex) {
					Log.e(Tag, "couldn't open thumbnail " + thumbUri + "; "
							+ ex);
				} catch (NullPointerException ex) {
					// we seem to get this if the file doesn't exist anymore
					Log.e(Tag, "couldn't open thumbnail " + thumbUri + "; "
							+ ex);
				} catch (OutOfMemoryError ex) {
					Log.e(Tag, "failed to allocate memory for thumbnail "
							+ thumbUri + "; " + ex);
				}
			}


    
[2] [转]应用 NSDate,NSCalendar, NSDateComponents 获得时间之差总结
    来源: 互联网  发布时间: 2014-02-18
[转]使用 NSDate,NSCalendar, NSDateComponents 获得时间之差总结
原文: http://blog.csdn.net/JHorn/archive/2009/09/27/4602491.aspx
方法一

NSDate* toDate1 = [ [ NSDate alloc] initWithString:@"2520-9-26 17:10:00 +0600" ];

NSTimeInterval distance = [ toDate1 timeIntervalSinceNow  ];

NSTimeInterval iDat = distance / ( 86400 ) ;

NSLog( @" From now to %@ diff: %f ", [toDate1 description ], iDat  );

[ toDate1 release ];

方法二
NSDate* toDate	 = [ [ NSDate alloc] initWithString:@"2009-9-29 0:0:00 +0600" ];

NSDate*  startDate	= [ [ NSDate alloc] init ];

NSCalendar* chineseClendar = [ [ NSCalendar alloc ] initWithCalendarIdentifier:NSGregorianCalendar ];

NSUInteger unitFlags =	NSHourCalendarUnit | NSMinuteCalendarUnit | 

NSSecondCalendarUnit | NSDayCalendarUnit

| NSMonthCalendarUnit | NSYearCalendarUnit;

NSDateComponents *cps = [ chineseClendar components:unitFlags fromDate:startDate  toDate:toDate  options:0];

NSInteger diffHour = [ cps hour ];

NSInteger diffMin    = [ cps minute ];

NSInteger diffSec   = [ cps second ];

NSInteger diffDay   = [ cps day ];

NSInteger diffMon  = [ cps month ];

NSInteger diffYear = [ cps year ];

NSLog(  @" From Now to %@, diff: Years: %d  Months: %d, Days; %d, Hours: %d, Mins:%d, sec:%d", 

[toDate description], diffYear, diffMon, diffDay, diffHour, diffMin,diffSec );

[ toDate release ];

[ startDate release ];

[ chineseClendar release ];


    
[3] 治理联系人
    来源: 互联网  发布时间: 2014-02-18
管理联系人
通过Android系统提供的接口,可以很方便的管理联系人信息。

添加

添加联系人
1.6上的代码
String peopleName = "name";
ContentValues personValues = new ContentValues();
// name
personValues.put(Contacts.People.NAME, peopleName);
/* STARRED 0 = Contacts, 1 = Favorites */
personValues.put(Contacts.People.STARRED, 0);
Uri newPersonUri = Contacts.People.createPersonInMyContactsGroup(
	getContentResolver(), personValues);


2.1时需要用下面的代码才可以添加
String peopleName = "name";
ContentValues personValues = new ContentValues();
// name
personValues.put(Contacts.People.NAME, peopleName);
newPersonUri = getContentResolver().insert(People.CONTENT_URI, personValues);


添加电话号码
根据TYPE的不同,可以添加不同类型的电话号码。
1.6上支持的TYPE有:TYPE_CUSTOM,TYPE_FAX_HOME,TYPE_FAX_WORK,TYPE_HOME,TYPE_MOBILE,TYPE_OTHER,TYPE_PAGER,TYPE_WORK。
Uri uri = null;
ContentValues values = new ContentValues();

// add phone number
String tel = "86-21-65432100";

if (!AppUtils.isEmpty(tel)) {
	values.clear();
	uri = Uri.withAppendedPath(newPersonUri, Contacts.People.Phones.CONTENT_DIRECTORY);
	values.put(Contacts.Phones.TYPE, Contacts.Phones.TYPE_HOME);
	values.put(Contacts.Phones.NUMBER, tel);
	getContentResolver().insert(uri, values);
}


添加Email地址
通过改变KIND的值,可以添加不同的联系方式。
1.6支持KIND_EMAIL,KIND_IM,KIND_ORGANIZATION,KIND_PHONE,KIND_POSTAL
// add email address
String email = "abc@com.cn";

if (!AppUtils.isEmpty(email)) {
	values.clear();
	uri = Uri.withAppendedPath(newPersonUri, Contacts.People.ContactMethods.CONTENT_DIRECTORY);
	values.put(Contacts.ContactMethods.KIND, Contacts.KIND_EMAIL);
	values.put(Contacts.ContactMethods.DATA, email);
	values.put(Contacts.ContactMethods.TYPE, Contacts.ContactMethods.TYPE_WORK);
	getContentResolver().insert(uri, values);
}


添加公司和职务
// add company name & title
String company = "Google?";
String position= "CEO!!!";

if (!AppUtils.isEmpty(company) || !AppUtils.isEmpty(position)) {
	values.clear();
	uri = Uri.withAppendedPath(newPersonUri, Contacts.Organizations.CONTENT_DIRECTORY);

	// company name
	if (!AppUtils.isEmpty(company)) {
		values.put(Contacts.Organizations.COMPANY, companyNameText);
	}
				
	// position
	if (!AppUtils.isEmpty(position)) {
		values.put(Contacts.Organizations.TITLE, positionNameText);
	}

	values.put(Contacts.Organizations.TYPE, Contacts.Organizations.TYPE_WORK);
	getContentResolver().insert(uri, values);
}


查询

要实现查询功能,可能需要有点SQL的基础。

查询人名
// the contents want to get
String projection[] = new String[] { People._ID, People.NAME };
// the name to be found
String name = "find me";
// start search
Cursor cur = getContentResolver().query(People.CONTENT_URI, 
projection, // select sentence
People.NAME + " = ?", // where sentence
new String[] { name }, // where values
People.NAME); // order by

if (cur.moveToFirst()) {
	// get the results
	do {
		String id = cur.getString(cur.getColumnIndex(People._ID));
		String name = cur.getString(cur.getColumnIndex(People.NAME));
	} while (cur.moveToNext());
}

// close while finish
if (cur != null) {
	cur.close();
}


通过修改projection的内容,可以取得不同的内容。
如果要获得电话号码,就可以改成(id由上面的代码获得)
String phoneProjection[] = new String[] { Contacts.Phones.PERSON_ID, Contacts.Phones.NUMBER };

Cursor phoneCursor = getContentResolver().query(Contacts.Phones.CONTENT_URI, 
phoneProjection, // select
Contacts.Phones.PERSON_ID + " = " + id, // where (another style)
null, 
Contacts.Phones.DEFAULT_SORT_ORDER); // order

if (phoneCursor.moveToFirst()) {
	// get the results
	do {
		String phone = phoneCursor.getString(phoneCursor.getColumnIndex(Contacts.Phones.NUMBER));
	} while (phoneCursor.moveToNext());
}

// close while finish
if (phoneCursor != null) {
	phoneCursor.close();
}


如果要获得email地址,稍微麻烦点
String emailProjection[] = new String[] { Contacts.Phones.PERSON_ID, Contacts.ContactMethods.KIND, Contacts.ContactMethods.DATA };

Cursor emailCursor = getContentResolver().query(Contacts.ContactMethods.CONTENT_URI, 
emailProjection, // select
Contacts.ContactMethods.PERSON_ID + " = " + id, // where
null, 
Contacts.ContactMethods.DEFAULT_SORT_ORDER); // order

if (emailCursor.moveToFirst()) {
	do {
		int kind = emailCursor.getInt(emailCursor.getColumnIndex(Contacts.ContactMethods.KIND));
		if (Contacts.KIND_EMAIL == kind) {
			email = emailCursor.getString(emailCursor.getColumnIndex(Contacts.ContactMethods.DATA));
		}
	} while (emailCursor.moveToNext());
}

// close while finish
if (emailCursor != null) {
	emailCursor.close();
}


修改

删除

    
最新技术文章:
▪Android开发之登录验证实例教程
▪Android开发之注册登录方法示例
▪Android获取手机SIM卡运营商信息的方法
▪Android实现将已发送的短信写入短信数据库的...
▪Android发送短信功能代码
▪Android根据电话号码获得联系人头像实例代码
▪Android中GPS定位的用法实例
▪Android实现退出时关闭所有Activity的方法
▪Android实现文件的分割和组装
▪Android录音应用实例教程
▪Android双击返回键退出程序的实现方法
▪Android实现侦听电池状态显示、电量及充电动...
▪Android获取当前已连接的wifi信号强度的方法
▪Android实现动态显示或隐藏密码输入框的内容
▪根据USER-AGENT判断手机类型并跳转到相应的app...
▪Android Touch事件分发过程详解
▪Android中实现为TextView添加多个可点击的文本
▪Android程序设计之AIDL实例详解
▪Android显式启动与隐式启动Activity的区别介绍
▪Android按钮单击事件的四种常用写法总结
▪Android消息处理机制Looper和Handler详解
▪Android实现Back功能代码片段总结
▪Android实用的代码片段 常用代码总结
▪Android实现弹出键盘的方法
▪Android中通过view方式获取当前Activity的屏幕截...
▪Android提高之自定义Menu(TabMenu)实现方法
▪Android提高之多方向抽屉实现方法
▪Android提高之MediaPlayer播放网络音频的实现方法...
▪Android提高之MediaPlayer播放网络视频的实现方法...
▪Android提高之手游转电视游戏的模拟操控
 


站内导航:


特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!

©2012-2021,,E-mail:www_#163.com(请将#改为@)

浙ICP备11055608号-3