Android工具类之手机组件调用工具类
2016-07-15 15:56
423 查看
/** * 手机组件调用工具类 */ public final class PhoneUtil { private static long lastClickTime; /** * Don't let anyone instantiate this class. */ private PhoneUtil() { throw new Error("Do not need instantiate!"); } /** * 调用系统发短信界面 * * @param activity Activity * @param phoneNumber 手机号码 * @param smsContent 短信内容 */ public static void sendMessage(Context activity, String phoneNumber, String smsContent) { if (phoneNumber == null || phoneNumber.length() < 4) { return; } Uri uri = Uri.parse("smsto:" + phoneNumber); Intent it = new Intent(Intent.ACTION_SENDTO, uri); it.putExtra("sms_body", smsContent); it.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); activity.startActivity(it); } /** * 判断是否为连击 * * @return boolean */ public static boolean isFastDoubleClick() { long time = System.currentTimeMillis(); long timeD = time - lastClickTime; if (0 < timeD && timeD < 500) { return true; } lastClickTime = time; return false; } /** * 获取手机型号 * * @param context 上下文 * @return String */ public static String getMobileModel(Context context) { try { String model = android.os.Build.MODEL; // 手机型号 return model; } catch (Exception e) { return "未知"; } } /** * 获取手机品牌 * * @param context 上下文 * @return String */ public static String getMobileBrand(Context context) { try { String brand = android.os.Build.BRAND; // android系统版本号 return brand; } catch (Exception e) { return "未知"; } } /** * 拍照打开照相机! * * @param requestcode 返回值 * @param activity 上下文 * @param fileName 生成的图片文件的路径 */ public static void toTakePhoto(int requestcode, Activity activity, String fileName) { Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); intent.putExtra("camerasensortype", 2);// 调用前置摄像头 intent.putExtra("autofocus", true);// 自动对焦 intent.putExtra("fullScreen", false);// 全屏 intent.putExtra("showActionIcons", false); try {//创建一个当前任务id的文件然后里面存放任务的照片的和路径!这主文件的名字是用uuid到时候在用任务id去查路径! File file = new File(fileName); if (!file.exists()) {//如果这个文件不存在就创建一个文件夹! file.mkdirs(); } Uri uri = Uri.fromFile(new File(fileName)); intent.putExtra(MediaStore.EXTRA_OUTPUT, uri); activity.startActivityForResult(intent, requestcode); } catch (Exception e) { e.printStackTrace(); } } /** * 打开相册 * * @param requestcode 响应码 * @param activity 上下文 */ public static void toTakePicture(int requestcode, Activity activity) { Intent intent = new Intent(Intent.ACTION_PICK, null); intent.setDataAndType(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, "image/*"); activity.startActivityForResult(intent, requestcode); } }
相关文章推荐
- android屏幕适配
- Android工具类之文件操作工具类
- Android Studio SQLite数据库应用(二)
- Android工具类之双击退出
- Android工具类之单位转换类
- Android工具类之日期操作工具类
- Android 实现自定义View
- 强烈推荐android studio用的几个插件
- Android工具类之颜色工具类 包括常用的色值
- Android 快速文件下载
- Android中dip、dp、sp、pt和px的区别
- 学习Android的点点滴滴--button click事件处理
- Android Material Design(一)史上最全的材料设计控件大全
- Android Material Design(一)史上最全的材料设计控件大全
- 详解android:scaleType属性
- Android 圆形头像的截取
- 文字跑马灯效果
- android studio 代码混淆如何忽略第三方jar包 The same input jar is specified twice
- android ScrollView 滚动到顶部
- Android实现对图片的缩放、剪切、旋转、存储