

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to share app data with other applications in android?
In android using implicit intent, we can send data with other applications using ACTION_SEND action. We have to call Intent.createChooser() to open default chooser of android mobile to send the data. it may same or different in Android mobiles.
This example demonstrates how to share app data with other applications in android.
Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.
Step 2 − Add the following code to res/layout/activity_main.xml.
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:id="@+id/layout" android:gravity="center" android:layout_height="match_parent" android:orientation="vertical"> <TextView android:id="@+id/data" android:layout_width="match_parent" android:gravity="center" android:textSize="30sp" android:text="www.tutorialspoint.com" android:layout_height="wrap_content" /> </LinearLayout>
In the above code, it contains textview, when user clicks on text view it going to send textview data with other applications.
Step 3 − Add the following code to src/MainActivity.java
package com.example.andy.myapplication; import android.annotation.TargetApi; import android.content.Intent; import android.os.Build; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.widget.TextView; public class MainActivity extends AppCompatActivity { public int counter; @TargetApi(Build.VERSION_CODES.O) @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); final TextView textView = findViewById(R.id.data); textView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent i = new Intent(); i.setAction(Intent.ACTION_SEND); i.setType("text/plain"); i.putExtra(android.content.Intent.EXTRA_TEXT, textView.getText().toString()); startActivity(Intent.createChooser(i, "Share to")); } }); } }
In the above code contains textview, when you click on textview, it going to send the data using intent.
Step 4 − No need to change of manifest.xml file
Let's try to run your application. I assume you have connected your actual Android Mobile device with your computer. To run the app from an android studio, open one of your project's activity files and click Run Icon from the toolbar. Select your mobile device as an option and then check your mobile device which will display your default screen −
This is an initial screen when you click on tutorialspoint.com it will open default chooser from your Android device as shown below -
Select any on application to send the data through that application. Either we can send the data for one person or post the data on your wall, it depends on chooser applications.
Click here to download the project code
- Related Questions & Answers
- How to work with Camera in an Android App?
- How to share intent from intentservice in android?
- How to add string and other data types for Listview in Android?
- How do I delete SharedPreferences data for my Android App?
- How to resize Image in Android App?
- How to use AutoCompleteTextView in Android App?
- How to parse JSONArray in Android app?
- How to create android app in facebook?
- How to integrate facebook in Android App?
- Working with Recycler View in Android App
- How to work with Camera in an Android App using Kotlin?
- How to check current running applications in Android?
- How to create Android Hello World App?
- How to consume Asp.Net WebAPI endpoints from other applications using C#?
- How to add new contacts in Android App?