How to use FileProvider in Uri.parse(file://” + filex.toString())?

how to use FileProvider for not getting error in android API >= 24?
I’ve tried FileProvider but it’s still getting error…
here is my source code

if(vid.equals("")) {
inFileName = img.substring(img.lastIndexOf('/') + 1);

File sdcard = Environment.getExternalStorageDirectory();
File filex = new File(sdcard, inDir + "/" + "IMAGE_" + inFileName);
if(filex.exists()) {
    if (inDialog.isShowing())
        inDialog.dismiss();

    Uri uri = Uri.parse("file://" + filex.toString());
    Intent i = new Intent();
    i.setAction(Intent.ACTION_VIEW);
    i.setDataAndType(uri, "image/*");
    inContext.startActivity(i);
} else {
    inTmp = Uri.parse(img);
    Image_DownloadId = DownloadData(inTmp, "IMAGE_" + inFileName);
}

}

this line is a little bit confusing because of using toString method
Uri.parse(“file://” + filex.toString())

Here is what I’m trying to do

                    if(vid.equals("")) {
                    inFileName = img.substring(img.lastIndexOf('/') + 1);

                    File sdcard = Environment.getExternalStorageDirectory();
                    File filex = new File(sdcard, inDir + "/" + "IMAGE_" + inFileName);
                    if(filex.exists()) {
                        if (inDialog.isShowing())
                            inDialog.dismiss();

                        Uri uri = FileProvider.getUriForFile(inContext, inContext.getApplicationContext().getPackageName() + ".provider", new File("file://" + filex.toString()));
                        Intent i = new Intent(Intent.ACTION_VIEW);
                        i.setDataAndType(uri, "image/*");
                        i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                        i.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
                        inContext.startActivity(i);
                    } else {
                        inTmp = Uri.parse(img);
                        Image_DownloadId = DownloadData(inTmp, "IMAGE_" + inFileName);
                    }

the application still getting force close

here is the log

java.lang.IllegalStateException: Binder has been finalized!