Android camera intent FileUriExposedException for SDK >= 24

后端 未结 2 608
小鲜肉
小鲜肉 2021-02-05 16:11

I use this code to get a picture from camera and put it on imageview:

  private void openCamera()
{
    mMediaUri =getOutputMediaFileUri(MEDIA_TYPE_IMAGE);

             


        
2条回答
  •  青春惊慌失措
    2021-02-05 16:39

    Instead of return Uri.fromFile(mediaFile); do

    return FileProvider.getUriForFile(MainActivity.this,
        BuildConfig.APPLICATION_ID + ".provider",
        mediaFile);
    

    That would require you to add a provider to the AndroidManifest:

    
    
            
        
    
    

    For AndroidX, use androidx.core.content.FileProvider

    And then create a provider_paths.xml file in xml folder under res folder.

    
    
        
    
    

    Read more: Full article

提交回复
热议问题