android 相簿 相機 獲取相片 相簿 2中方式
阿新 • • 發佈:2018-12-14
// 相簿選取 Intent intent = new Intent(Intent.ACTION_GET_CONTENT).setType("image/*"); intent.addCategory(Intent.CATEGORY_OPENABLE); intent.setDataAndType(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, "image/*"); startActivityForResult(intent, Constants.REQUEST_CODE_GALLERY); // 相簿選取 Intent intent = new Intent( Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); startActivityForResult(intent, Constants.REQUEST_CODE_GALLERY); // 拍照 File temp = new File(PicUtils.PATH); Uri imageFileUri = Uri.fromFile(temp);//獲取檔案的Uri Intent it = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);//跳轉到相機Activity it.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, imageFileUri);//告訴相機拍攝完畢輸出圖片到指定的Uri startActivityForResult(it, Constants.REQUEST_CODE_PHOTOGRAPH);