当前位置: 编程技术>移动开发
本页文章导读:
▪解决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
方法一
方法二
原文: 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上的代码
2.1时需要用下面的代码才可以添加
添加电话号码
根据TYPE的不同,可以添加不同类型的电话号码。
1.6上支持的TYPE有:TYPE_CUSTOM,TYPE_FAX_HOME,TYPE_FAX_WORK,TYPE_HOME,TYPE_MOBILE,TYPE_OTHER,TYPE_PAGER,TYPE_WORK。
添加Email地址
通过改变KIND的值,可以添加不同的联系方式。
1.6支持KIND_EMAIL,KIND_IM,KIND_ORGANIZATION,KIND_PHONE,KIND_POSTAL
添加公司和职务
查询
要实现查询功能,可能需要有点SQL的基础。
查询人名
通过修改projection的内容,可以取得不同的内容。
如果要获得电话号码,就可以改成(id由上面的代码获得)
如果要获得email地址,稍微麻烦点
修改
删除
通过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();
}
修改
删除
最新技术文章: