I try to open PDF file in Pie? but it does not open. I don't get any error. What is the issue? PDF file does not open. Only black screen is shown. In logcat no errors show. What is wrong?
Intent intent = new Intent(Intent.ACTION_VIEW);
Uri outputFileUri;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
outputFileUri = FileProvider.getUriForFile(this, BuildConfig.APPLICATION_ID + ".provider", file);
} else
outputFileUri = Uri.fromFile(file);
Log.e("TAG", "outputFileUri-> " + outputFileUri);
intent.setDataAndType(outputFileUri, "application/pdf");
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
try {
startActivity(intent);
} catch (ActivityNotFoundException e) {
Toast.makeText(this, "No Application available to view pdf", Toast.LENGTH_LONG).show();
}
AndroidManifest.xml
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths" />
</provider>
<paths>
<external-path
name="external_files"
path="." />
<external-path
name="external"
path="." />
<external-files-path
name="external_files"
path="." />
<cache-path
name="cache"
path="." />
<external-cache-path
name="external_cache"
path="." />
<files-path
name="files"
path="." />
How Can I resolve this issue? I referred many links but did not get solution. I also tried many codes but no help.