标签:ram ace draw stream cti 通讯录 roi oca nim
一般用在读取手机通讯录上传,这一块比較多。
import java.util.ArrayList; import java.util.List; import android.content.ContentResolver; import android.content.Context; import android.database.Cursor; import android.provider.ContactsContract.CommonDataKinds.Phone; import android.text.TextUtils; import com.iss.starwish.bean.PhoneContact; /** * 读取手机联系人信息 */ public class ReadPhoneContactUtil { /** * 通过内容观察者,或者手机联系人相关的信息 **/ public static List<PhoneContact> getPhoneContacts(Context mContext) { List<PhoneContact> phoneContacts = new ArrayList<PhoneContact>(); ContentResolver resolver = mContext.getContentResolver(); String[] PHONES_PROJECTION = new String[] { Phone.NUMBER,Phone.DISPLAY_NAME }; // 获取手机联系人 Cursor phoneCursor = resolver.query(Phone.CONTENT_URI,PHONES_PROJECTION, null, null, null); if (phoneCursor != null) { while (phoneCursor.moveToNext()) { // 得到手机号码 String phoneNumber = phoneCursor.getString(0); // 当手机号码为空的或者为空字段 跳过当前循环 if (TextUtils.isEmpty(phoneNumber)) continue; // 得到联系人名称 String contactName = phoneCursor.getString(1); phoneContacts.add(new PhoneContact(contactName,phoneNumber)); } } return phoneContacts; } }
这个最经常使用的是在国际化或者一键改动主题这一块。依据不同的语言环境,切换不同的字符串标识。
依据不同的文件名称,切换不同的主题
package net.tianyouwang.utils;
import android.content.Context;
/**
* 通过字段名称来动态的获取资源的id,再来使用。此类,能够通过字段名称动态获取id。
*/
public class ResourceUtil {
public static int getLayoutId(Context context, String paramString) {
return context.getResources().getIdentifier(paramString, "layout",
context.getPackageName());
}
public static int getStringId(Context context, String paramString) {
return context.getResources().getIdentifier(paramString, "string",
context.getPackageName());
}
public static int getDrawableId(Context context, String paramString) {
return context.getResources().getIdentifier(paramString,
"drawable", context.getPackageName());
}
public static int getStyleId(Context context, String paramString) {
return context.getResources().getIdentifier(paramString,
"style", context.getPackageName());
}
public static int getId(Context context, String paramString) {
return context.getResources().getIdentifier(paramString,
"id", context.getPackageName());
}
public static int getColorId(Context context, String paramString) {
return context.getResources().getIdentifier(paramString,
"color", context.getPackageName());
}
public static int getAnimationId(Context context, String paramString) {
return context.getResources().getIdentifier(paramString,
"anim", context.getPackageName());
}
public static int getBooleanId(Context context, String paramString) {
return context.getResources().getIdentifier(paramString,
"bool", context.getPackageName());
}
public static int getArrayId(Context context, String paramString) {
return context.getResources().getIdentifier(paramString,
"array", context.getPackageName());
}
}
import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import android.os.Environment; import android.os.StatFs; import android.text.TextUtils; /*** * SDCard的剩余容量推断操作 * */ public class SDCardAvailableUtils { private static final int imageSize = 1*1024*1024;//1M public static boolean isExistSDCard() { if (android.os.Environment.getExternalStorageState().equals( android.os.Environment.MEDIA_MOUNTED) && getAvailableStore(Environment.getExternalStorageDirectory().getPath()) > imageSize) { return true; } else return false; } public static void saveDatatoLocalFile(String data, String filePath) { if (!TextUtils.isEmpty(data) && !TextUtils.isEmpty(filePath)) { File file = new File(filePath); FileOutputStream outStr = null; try { if (!file.exists()) { file.createNewFile(); } outStr = new FileOutputStream(file); if (outStr != null) { outStr.write(data.getBytes()); outStr.flush(); } } catch (IOException e) { e.printStackTrace(); } finally { if (outStr != null) { try { outStr.close(); } catch (IOException e) { e.printStackTrace(); } finally { outStr = null; } } } } } /** * 获取存储卡的剩余容量,单位为字节 * * @param filePath * @return availableSpare */ public static long getAvailableStore(String filePath) { // 取得sdcard文件路径 StatFs statFs = new StatFs(filePath); // 获取block的SIZE long blocSize = statFs.getBlockSize(); // 获取BLOCK数量 long totalBlocks = statFs.getBlockCount(); // 可使用的Block的数量 long availaBlock = statFs.getAvailableBlocks(); long total = totalBlocks * blocSize;//总的存储空间 long availableSpare = availaBlock * blocSize;//当前可用存储空间 return availableSpare; } }
标签:ram ace draw stream cti 通讯录 roi oca nim
原文地址:http://www.cnblogs.com/wzzkaifa/p/6815999.html