private void startPhotoAlbum(){Intent intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);startActivityForResult(intent, UConstants.GETIMAGE);}private String urlTempPic = "";private void startCamera(){Intent i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);urlTempPic = getImagePath();i.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(urlTempPic)));startActivityForResult(i, UConstants.CAPUTRE);}public static String getImagePath(){String path = null;String dir = getExternalStoragePublicDirectory(UDataStorage.Dir_Pictures) + "/pyj/temp/pics/";path = dir + System.currentTimeMillis() + ".jpg";ensureDir(dir);return path;}public static boolean ensureDir(String dir){boolean result = false;File file = new File(dir);if (!file.exists())result = file.mkdirs();return result;}public static File getExternalStoragePublicDirectory(String type){File file = null;String path = Environment.getExternalStorageDirectory().getAbsolutePath() + "/" + type;file = new File(path);if (!file.exists())file.mkdirs();return file;}

private static final int DIALOG_YES_NO_LONG_MESSAGE = 1;@Overrideprotected Dialog onCreateDialog(int id) {// TODO Auto-generated method stubswitch (id) {case DIALOG_YES_NO_LONG_MESSAGE:            return new AlertDialog.Builder(JSelectEventTypeActivity.this,AlertDialog.THEME_HOLO_LIGHT)                .setTitle("提示")                .setPositiveButton("从相册", new DialogInterface.OnClickListener() {                    public void onClick(DialogInterface dialog, int whichButton) {                            /* User clicked OK so do some stuff */                    startPhotoAlbum();                    }                })                .setNeutralButton("从相机", new DialogInterface.OnClickListener() {                    public void onClick(DialogInterface dialog, int whichButton) {                        /* User clicked Something so do some stuff */                    startCamera();                    }                })                .setNegativeButton("不需要", new DialogInterface.OnClickListener() {                    public void onClick(DialogInterface dialog, int whichButton) {                    }                })                .create();}return null;}

@Overrideprotected void onActivityResult(int requestCode, int resultCode, Intent data) {// TODO Auto-generated method stubswitch (resultCode) {case RESULT_OK:if (requestCode == UConstants.CAPUTRE){// Load up the image's dimensions not the image itselftry {BitmapFactory.Options bmpFactoryOptions = new BitmapFactory.Options();bmpFactoryOptions.inJustDecodeBounds = true;Bitmap bmp = BitmapFactory.decodeFile(urlTempPic,bmpFactoryOptions);int widthRatio = (int) Math.ceil(bmpFactoryOptions.outWidth / (float) 1080);if (widthRatio > 1){bmpFactoryOptions.inSampleSize = widthRatio;}bmpFactoryOptions.inJustDecodeBounds = false;bmp = BitmapFactory.decodeFile(urlTempPic, bmpFactoryOptions);} catch (Exception e) {// TODO Auto-generated catch blocke.printStackTrace();}}else if (requestCode == UConstants.GETIMAGE){Uri imageFileUri = data.getData();try {BitmapFactory.Options bmpFactoryOptions = new BitmapFactory.Options();bmpFactoryOptions.inJustDecodeBounds = true;Bitmap bmp = BitmapFactory.decodeStream(getContentResolver().openInputStream(imageFileUri), null, bmpFactoryOptions);int widthRatio = (int) Math.ceil(bmpFactoryOptions.outWidth/ (float) 1080);if (widthRatio > 1) {bmpFactoryOptions.inSampleSize = widthRatio;}bmpFactoryOptions.inJustDecodeBounds = false;bmp = BitmapFactory.decodeStream(getContentResolver().openInputStream(imageFileUri),null, bmpFactoryOptions);} catch (Exception e) {// TODO: handle exception}}break;default:break;}}



更多相关文章

  1. android 弹出带按钮的对话框
  2. Android相机开发那些坑
  3. android Multiple markers at this line - The type java.lang.C
  4. 【Android学习笔记】AutoCompleteTextView(数组在代码中)
  5. Android(安卓)Studio自带模拟器读写SDcard不成功的解决办法
  6. Android(安卓)调用相册 拍照 实现系统控件缩放 切割图片
  7. Android自动提示文本框(AutoCompleteTextView)
  8. eclipse添加android插件错误处理方法
  9. Android(安卓)调用相册 拍照 实现系统控件缩放 切割图片

随机推荐

  1. Android创建和使用数据库详细指南(7)
  2. 【Android 设计】:启航_ 创作意图 | 设计
  3. Android实现网络视频播放
  4. android程序实现简单拨号器功能
  5. Android简单音乐播放器
  6. 按powerkey唤醒启动上层Andord
  7. android:layout_gravity 和 android:grav
  8. android studio创建新项目color.xml文件
  9. java.lang.NoClassDefFoundError: com.go
  10. 真正的机器人操作系统---Android