I was trying to build an application through which users can share complete screenshots of the current screen and share through the various apps.
While developing, I Stuck at the error
exposed beyond app through ClipData.Item.getUri Due to that app gets crashed when I pressed on the Share Button.
I have resolved this issue while debugging, and I thought it would be great To make an article and solve other user problems.
Table of Contents
Fix the issue
This issue arises after Android SDK 24 or android 7.0. Before that, we are able to access file content using
file:/// after 7.0, we have to use
content:// which is a more secure way to access files.
To learn more, you can read the documentation. Without taking any further moment, let’s fix the above issue.
When we want to access file content outside the application storage, we need to use
Open the Activity file and use the below code to get the URI of a file
Inside the parameter pass, the following code first parameter will accept the current activity details for that we have used
The second parameters are the authority where you need to provide app signature along with .provider
BuildConfig.APPLICATION_IDShow package name.
getLocalClassName()It will show the current activity class name.
.providersubclass of ContentProvider to access data
In the last parameter provide the path of Image file that you have already created prior to this
We need to create an XML path for that right click on the res folder and create a new Android Resource Directory, save the directory name with xml.
Under the xml directory, please create a new xml file save with file_path.xml, open it and add the below command
Add provider in AndroidManifest
Once you complete the above process Open
AndroidManifest and add the below command inside the
android:authorities over here, use your application
package name with
class name where you have linked the URI along with
<meta-data> tag on
android: resources pass the above created xml file details.
Rest all, keep it the same as above and try to run applications, and you will not get the error if you follow the above steps correctly.
That’s it to resolve
exposed beyond app through ClipData.Item.getUri If the problem didn’t resolve, go through the article again.
If the problem still persists, use Pastebin and share your code with us we will try to fix it.
Please leave the comment If you found the article useful.
A man with a tech effusive, who has explored some of the amazing technology stuff and exploring more, While moving towards, I had a chance to work on Android Development, Linux, AWS, DevOps with several Open source tools.
One of my life mottos “Always be lifelong Students.”