This is the final working code, thanks to all to let me know the FileProvider
AndroidManifest.xml
<manifest>
...
<application>
...
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="com.myproject.myapp.fileprovider"
android:grantUriPermissions="true"
android:exported="false">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/filepaths" />
</provider>
res/xml/filepaths.xml
<?xml version="1.0" encoding="utf-8"?>
<paths>
<external-path path="/" name="myInternalMemory" />
</paths>
MainActivity.java
Uri contentUri = FileProvider.getUriForFile(getApplicationContext(), "com.myproject.myapp.fileprovider", new File(filenamePath));
context.grantUriPermission("com.myproject.myapp.fileprovider", contentUri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setData(contentUri);
intent.setFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
//support from Android 4.1 (API level 16) to Android 5.1 (API level 22) inclusive
intent.setClipData(ClipData.newRawUri("", contentUri));
intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
context.startActivity(intent);