Android Projects

Android Development Books

Tuesday

How filter ACTION_SEND list to show Email apps


This example will show how filter ACTION_SEND list to show email apps only.
Algorithm:
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="http://schemas.android.com/apk/res/android"
        android:orientation="vertical" android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <TextView android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                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"
                android:layout_height="wrap_content"android:layout_width="wrap_content"></Button>
</LinearLayout>
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.
Steps:
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 ActionSendFilterActivity.java file and write following code there:
package com.example.actionsendfilter;
import java.io.File;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
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. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
       
        Button cancelRecordButton = (Button) findViewById(R.id.Button);
                cancelRecordButton.setOnClickListener(new OnClickListener() {
                        @Override
                        public void onClick(View v) {
                                  Intent emailIntent = newIntent(android.content.Intent.ACTION_SEND);
                                        emailIntent.setType("text/plain");
                                        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");
                                        emailIntent.setType("vnd.android.cursor.dir/email");
                                        startActivity(emailIntent);
                        }
                });
       
     
    }
}
3.) Compile and build the project.
4.) Run on simulator for the output which must have email application configured.
Output


More details about this article click following link.  http://www.edumobile.org/android/
Share this post
  • Share to Facebook
  • Share to Twitter
  • Share to Google+
  • Share to Stumble Upon
  • Share to Evernote
  • Share to Blogger
  • Share to Email
  • Share to Yahoo Messenger
  • More...

0 comments

Thanks for your comment

:) :-) :)) =)) :( :-( :(( :d :-d @-) :p :o :>) (o) [-( :-? (p) :-s (m) 8-) :-t :-b b-( :-# =p~ :-$ (b) (f) x-) (k) (h) (c) cheer

Related Posts Plugin for WordPress, Blogger...
© Google Android Lovers
Designed by BlogThietKe Cooperated with Duy Pham
Released under Creative Commons 3.0 CC BY-NC 3.0