Saturday, September 8, 2012

Action Send Filter In Android

This example will show how filter ACTION_SEND list to show email apps only.
1.) Create a new project by File-> New -> Android Project name it ActionSendFilter.
2.) You will see some default code into your main.xml, strings.xml and android manifest file.
3.) Write following into main.xml file:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android=""
        android:orientation="vertical" android:layout_width="fill_parent"

        <TextView android:layout_width="fill_parent"
                android:text="This application shows how you can filter ACTION_SEND list to show only email allications.\n\n" />
        <Button android:text="Share Via Email" android:id="@+id/Button"
4.) Your launcher activity ActionSendFilterActivity will have one default functions OnCreate().
5.) Your device or simulator must have at least one email application such as gmail, ymail or default email configured to run this application.
1.) Create a project named ActionSendFilter and set the information as stated in the image.
Build Target: Android 2.1
Application Name: ActionSendFilter
Package Name: com.example. actionsendfilter
Activity Name: ActionSendFilterActivity
Min SDK Version: 7

2.) Open file and write following code there:
package com.example.actionsendfilter;
import android.content.Intent;
import android.os.Bundle;
import android.os.Environment;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class ActionSendFilterActivity extends Activity {
    /** Called when the activity is first created. */
    public void onCreate(Bundle savedInstanceState) {
        Button cancelRecordButton = (Button) findViewById(;
                cancelRecordButton.setOnClickListener(new OnClickListener() {
                        public void onClick(View v) {
                                  Intent emailIntent = newIntent(android.content.Intent.ACTION_SEND);
                                        emailIntent.putExtra(android.content.Intent.EXTRA_TITLE,"Send via");
                                        emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,"See the route I found on GeoTracker App");
                                        String imagePath;
                                        File f = newFile(Environment.getExternalStorageDirectory()+"/abc.txt");
                                        imagePath = f.getPath();
                                        emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://"+imagePath));
                                        emailIntent.putExtra(android.content.Intent.EXTRA_TEXT"This is a Demo email to show how to filter ACTION_SEND for emails only");
3.) Compile and build the project.
4.) Run on simulator for the output which must have email application configured.

No comments:

Post a Comment