Giter Club home page Giter Club logo

Comments (1)

429329513wanting avatar 429329513wanting commented on August 24, 2024

解决了,android7.0,读取照片需要FileProvider.getUriForFile 问题
参考链接:https://blog.csdn.net/yy1300326388/article/details/52787853

把AndroidImagePicker类 takePicture方法修改如下:
public void takePicture(Fragment fragment, int requestCode) throws IOException {

    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    //Intent takePictureIntent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
    takePictureIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    // Ensure that there's a camera activity to handle the intent
    if (takePictureIntent.resolveActivity(fragment.getContext().getPackageManager()) != null) {
        // Create the File where the photo should go
        //File photoFile = createImageFile();
        File photoFile = createImageSaveFile(fragment.getContext());
        // Continue only if the File was successfully created
        if (photoFile != null) {

            Uri uri = null;
            if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.N){

                uri = FileProvider.getUriForFile(fragment.getContext(), "com.pizidea.imagepicker.fileprovider", photoFile);

            }else {

                uri = Uri.parse(photoFile.getAbsolutePath());
            }

            takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT,uri);
            Log.i(TAG,"=====file ready to take photo:"+photoFile.getAbsolutePath() );
        }
    }
    fragment.startActivityForResult(takePictureIntent, requestCode);

}

from androidimagepicker.

Related Issues (10)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.