How to use FileProvider in Uri.parse(file://" + filex.toString()) & Java.lang.RuntimeException Error Receiving BroadCast Intent

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);
}

}

First log

android.os.FileUriExposedException: file:///storage/emulated/0/Images/IMAGE_26072028_383759662086144_8624202031520808960_n.jpg exposed beyond app through Intent.getData()

this error because of using android api >= 24 and need to use FileProvider, so I try to use it.. 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

01-14 17:48:24.288 23382-23382/com.my.app E/AndroidRuntime: FATAL EXCEPTION: main Process: com.my.app, PID: 23382 java.lang.IllegalArgumentException: Failed to find configured root that contains /file:/storage/emulated/0/Images/IMAGE_26072028_383759662086144_8624202031520808960_n.jpg at android.support.v4.content.FileProvider$SimplePathStrategy.getUriForFile(FileProvider.java:711) at android.support.v4.content.FileProvider.getUriForFile(FileProvider.java:400) at com.my.app.App$Loading$1.onClick(Saver.java:128) at android.view.View.performClick(View.java:5619) at android.view.View$PerformClick.run(View.java:22295) at android.os.Handler.handleCallback(Handler.java:754) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:163) at android.app.ActivityThread.main(ActivityThread.java:6321) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:880) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:770)

got another error in this line

String filename = cursor.getString(filenameIndex);

BroadcastReceiver downloadReceiver = new BroadcastReceiver() {

    @Override
    public void onReceive(Context context, Intent intent) {

        //check if the broadcast message is for our Enqueued download
        long referenceId = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1);

        if(referenceId == Image_DownloadId) {

            DownloadManager.Query ImageDownloadQuery = new DownloadManager.Query();
            //set the query filter to our previously Enqueued download
            ImageDownloadQuery.setFilterById(Image_DownloadId);

            //Query the download manager about downloads that have been requested.
            Cursor cursor = downloadManager.query(ImageDownloadQuery);
            if(cursor.moveToFirst()){
                int filenameIndex = cursor.getColumnIndex(DownloadManager.COLUMN_LOCAL_FILENAME);
                String filename = cursor.getString(filenameIndex);
                Uri uri = Uri.parse("file://" + filename);

                Intent i = new Intent();
                if(inTenTipe.equals("repost")) {
                    i.setAction(Intent.ACTION_SEND);
                    i.putExtra(Intent.EXTRA_STREAM, uri);
                    i.setType("image/*");
                }else {
                    i.setAction(Intent.ACTION_VIEW);
                    i.setDataAndType(uri, "image/*");
                }

                try {
                    if (inDialog.isShowing())
                        inDialog.dismiss();
                    inContext.startActivity(i);
                } catch (android.content.ActivityNotFoundException ex) {
                    File file = new File(filename);
                    boolean deleted = file.delete();
                    Image_DownloadId = DownloadData(inTmp, "IMAGE_" + inFileName);
                }

            }

        }

Log

FATAL EXCEPTION: main Process: com.my.app, PID: 29139 java.lang.RuntimeException: Error receiving broadcast Intent { act=android.intent.action.DOWNLOAD_COMPLETE flg=0x10 pkg=com.my.app (has extras) } in com.my.app.APP$1@cc58ede at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:1140) at android.os.Handler.handleCallback(Handler.java:754) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:163) at android.app.ActivityThread.main(ActivityThread.java:6321) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:880) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:770) Caused by: java.lang.SecurityException: COLUMN_LOCAL_FILENAME is deprecated; use ContentResolver.openFileDescriptor() instead at android.app.DownloadManager$CursorTranslator.getString(DownloadManager.java:1791) at com.my.app.App$1.onReceive(Saver.java:616) at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:1130) at android.os.Handler.handleCallback(Handler.java:754)  at android.os.Handler.dispatchMessage(Handler.java:95)  at android.os.Looper.loop(Looper.java:163)  at android.app.ActivityThread.main(ActivityThread.java:6321)  at java.lang.reflect.Method.invoke(Native Method)  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:880)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:770)