美文网首页我爱编程
相机7.0拍照适配

相机7.0拍照适配

作者: 西决_7e15 | 来源:发表于2018-04-16 15:36 被阅读0次

    private UriimageUri;

    //跳转相机

    private void toCamera() {

    File outputImage =new File(Environment.getExternalStorageDirectory(),

                TAKE_PHOTO_NAME);

        try {

    if (outputImage.exists()) {

    outputImage.delete();

            }

    outputImage.createNewFile();

        }catch (IOException e) {

    e.printStackTrace();

        }

    if (Build.VERSION.SDK_INT >=24) {

    imageUri = FileProvider.getUriForFile(getActivity(),

                    getContext().getApplicationContext().getPackageName()+".provider", outputImage);

        }else {

    imageUri = Uri.fromFile(outputImage);

        }

    //启动相机程序

        Intent intent =new Intent("android.media.action.IMAGE_CAPTURE");

        intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);

        startActivityForResult(intent, TakePhotoEnum.TAKE_PICTURE.getRequestCode());

    }

    case 201:

    if (resultCode ==RESULT_OK) {

    File file =new File(Environment.getExternalStorageDirectory(), TAKE_PHOTO_NAME);

            mListImage.remove(mListImage.size()-1);

            mListImage.add(new PostImageBean(file.getAbsolutePath(),file));

            mListImage.add(new PostImageBean(""));

            mBaseRecyclerAdapter.init(mListImage);

            mBaseRecyclerAdapter.notifyDataSetChanged();

        }

    break;

    相关文章

      网友评论

        本文标题:相机7.0拍照适配

        本文链接:https://www.haomeiwen.com/subject/qnrekftx.html