Software⏱️ 2 min read📅 2026-05-30

How to Fix: android.os.FileUriExposedException: file:///storage/emulated/0/test.txt exposed beyond app through Intent.getData()

The issue is caused by the change in Android Nougat (API level 24) that restricts UriExposureException. To fix this, use the new method Intent.createChooser() instead of Intent.setDataAndType().

Quick Answer: Replace intent.setDataAndType() with intent.addCategory(Intent.CATEGORY_BROWSABLE) and intent.setType(

The Android OS has introduced a new security feature in Android Nougat (API level 24) and later versions to prevent file sharing between apps. This feature is known as File URI Exposure, which restricts the use of file URIs exposed through Intent.getData().

⚠️ Common Causes

  • The issue occurs when an app tries to open a file from the SD card using Intent.getData().

✅ Best Solutions to Fix It

Method 1: Using the 'EXTRA_STREAM' Intent Flag

  1. Step 1: Add the 'EXTRA_STREAM' intent flag to your Intent when opening the file.

Method 2: Using a ContentResolver

  1. Step 1: Use a ContentResolver to open the file instead of Intent.getData().

✨ Wrapping Up

To resolve this issue, you can use either Method 1 or Method 2. By adding the 'EXTRA_STREAM' intent flag or using a ContentResolver, you can prevent the Android OS from throwing FileUriExposedException.

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions