Most of the time while using an app we want to share images from the app to another app. While using Many Social Media Platforms we find this feature to be very useful when we want to share information from one app to another. The Android Intent resolver is used when sending data to another app as part of a well-defined task flow. To use the Android intent resolver, create an intent and add extras. Here we are going to understand how to do that.
Note: If you want to share the Text of Your App with Another App in Android then please refer to this.
Step by Step Implementation
Step 1: Create a new Project
To create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio. Note that select Java as the programming language.
Step 2: Working with the AndroidManifest.xml file
Add the following permission to the AndroidManifest.xml file
<uses-permission android:name=”android.permission.READ_EXTERNAL_STORAGE” />
<uses-permission android:name=”android.permission.WRITE_EXTERNAL_STORAGE” />
Add the following lines inside the <application> tag and after the </acticty> tag.
Below is the complete code for the AndroidManifest.xml file
Step 3: Create a new XML file
Create an XML directory in res and then create a paths.xml file in it. A file Provider can only generate a content URI for files in directories that we specify beforehand. We specify a directory, specify its storage area and path in XML, using child elements of the <paths> element. Below is the video of creating the XML file.
Step 4: Working with the activity_main.xml file
Go to the activity_main.xml file and refer to the following code. Below is the code for the activity_main.xml file.
Reference article: How to Add Image to Drawable Folder in Android Studio?
Step 5: Working with the MainActivity.java file
Go to the MainActivity.java file and refer to the following code. Below is the code for the MainActivity.java file. Comments are added inside the code to understand the code in more detail.
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.