Android receive data from other applications

Some Android applications need an ability to receive data sent from other applications. For example an image viewer application is able to view an image that is clicked to view from any location on Android device. Similarly, and text editor application is able to view a text file clicked to open from the external storage. To achieve this goal, first you need to tell Android system the action that is performed on the data and the type of data that can be received in your application by defining intent filter in the AndroidManest.xml file. Then in your code, you will able to get the data and process it.

Now to have an example application on receiving data sent from other applications, you need to create a new Android project. Then modify the activity_main.xml file to add an ImageView. The example application is able to view an image that is clicked to view from any location of an Android device.

<LinearLayout xmlns:android=""

After that, open the AndroidManifest.xml file to define an intent filter to tell Android that the action to be performed on the data is action view and the type of data is image. The DEFAULT category allows the Android system to capture intents that do not have a category. In most cases, we use this category.

<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android=""
   android:versionName="1.0" >

     android:targetSdkVersion="17" />

     android:theme="@style/AppTheme" >
        android:label="@string/app_name" >
           <action android:name="android.intent.action.MAIN" />
           <category android:name="android.intent.category.LAUNCHER" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />


Finally in the onCreate() method of the MainActivity class (in the file), you need code to get the image data, and display the image in the ImageView. The image data stored in the intent object sent from other applications can be gotten by using the getParcelableExtra() method of the Intent.

package com.example.androidexample;
import android.os.BatteryManager;
import android.os.Bundle;
import android.content.Intent;
import android.content.IntentFilter;
import android.view.Menu;
import android.widget.ImageView;
import android.widget.Toast;

public class MainActivity extends Activity {

protected void onCreate(Bundle savedInstanceState) {
Intent intent=getIntent();
   String action=intent.getAction();    
   String type =intent.getType();
   if(Intent.ACTION_VIEW.equals(action) && type!="") {
     if (type.startsWith("image/")) {
     ImageView imgView=(ImageView)findViewById(;
     Uri imgUri=intent.getParcelableExtra(Intent.EXTRA_STREAM);


public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(, menu);
return true;



Posted by: Dara | post date: 09-07-2014 | Subject: Android Apps Development

write programming tip

This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages:
C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.