-2

android manifest code Email.java email.xml files are below

 <?xml version="1.0" encoding="utf-8"?>
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.shubham.myapplication" >

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".Splash"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name=".MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action     
 android:name="com.example.shubham.myapplication.MAINACTIVITY" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
    <activity
        android:name=".Menu"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="com.example.shubham.myapplication.MENU" 
   />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
    <activity
        android:name=".TextPlay"
        android:label="@string/app_name" >

    </activity>
    <activity
        android:name=".TextPlay1"
        android:label="@string/app_name" >

    </activity>
    <activity
        android:name=".Email"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.content.Intent.ACTION_SEND" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>

       </application>

      </manifest>

Email.java

  package com.example.shubham.myapplication;

  import android.app.Activity;
  import android.content.Intent;
  import android.os.Bundle;
  import android.view.View;
  import android.widget.Button;
  import android.widget.EditText;

  public class Email extends Activity implements View.OnClickListener {

EditText personsEmail, intro, personsName, stupidThings, hatefulAction,
        outro;
String emailAdd, beginning, name, stupidAction, hatefulAct, out;
Button sendEmail;

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.email);
    initializeVars();
    sendEmail.setOnClickListener(this);
}

private void initializeVars() {
    // TODO Auto-generated method stub
    personsEmail = (EditText) findViewById(R.id.etEmails);
    intro = (EditText) findViewById(R.id.etIntro);
    personsName = (EditText) findViewById(R.id.etName);
    stupidThings = (EditText) findViewById(R.id.etThings);
    hatefulAction = (EditText) findViewById(R.id.etAction);
    outro = (EditText) findViewById(R.id.etOutro);
    sendEmail = (Button) findViewById(R.id.bSentEmail);
}

public void onClick(View v) {
    // TODO Auto-generated method stub

    convertEditTextVarsIntoStringsAndYesThisIsAMethodWeCreated();
    String emailaddress[] = { emailAdd };
    String message = "Well hello "
            + name
            + " I just wanted to say "
            + beginning
            + ".  Not only that but I hate when you "
            + stupidAction
            + ", that just really makes me crazy.  I just want to make    
  you "
            + hatefulAct
            + ".  Welp, thats all I wanted to chit-chatter about, oh and"
            + out
            + ".  Oh also if you get bored you should check out your 
 stupidity"
            + '\n' + "PS. I think I love you...   :(";
    Intent ourIntent = new Intent(Intent.ACTION_SEND);
    ourIntent.putExtra(Intent.EXTRA_EMAIL,emailaddress);
    ourIntent.putExtra(Intent.EXTRA_SUBJECT,"I judgsjug you");
    ourIntent.putExtra(Intent.EXTRA_TEXT,message);
    startActivity(ourIntent);


}

private void convertEditTextVarsIntoStringsAndYesThisIsAMethodWeCreated() 
 {
    // TODO Auto-generated method stub
    emailAdd = personsEmail.getText().toString();
    beginning = intro.getText().toString();
    name = personsName.getText().toString();
    stupidAction = stupidThings.getText().toString();
    hatefulAct = hatefulAction.getText().toString();
    out = outro.getText().toString();
 }



 }

email.xml

  <?xml version="1.0" encoding="utf-8"?>
  <LinearLayout    
   xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:weightSum="100" android:layout_height="match_parent">
<ScrollView android:layout_weight="30" android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <LinearLayout android:orientation="vertical"
        android:layout_width="match_parent"   
   android:layout_height="match_parent">
        <TextView android:text="Email address(es):"
            android:layout_width="wrap_content"     
   android:layout_height="wrap_content"></TextView>
        <EditText android:layout_height="wrap_content"
            android:layout_width="match_parent" 
 android:id="@+id/etEmails">
        </EditText>
        <TextView android:text="Hateful Intro:"
            android:layout_width="wrap_content" 
 android:layout_height="wrap_content"></TextView>
        <EditText android:layout_height="wrap_content"
            android:layout_width="match_parent" 
android:id="@+id/etIntro"></EditText>
        <TextView android:text="Person's name" 
android:layout_width="wrap_content"
            android:layout_height="wrap_content"></TextView>
        <EditText android:layout_height="wrap_content"
            android:layout_width="match_parent" android:id="@+id/etName">        
    </EditText>
        <TextView android:text="Stupid Things that this Person does"
            android:layout_width="wrap_content" 
    android:layout_height="wrap_content"></TextView>
        <EditText android:layout_height="wrap_content"
            android:layout_width="match_parent"
    android:id="@+id/etThings"></EditText>
        <TextView android:text="What you want to do to this person:"
            android:layout_width="wrap_content" 
     android:layout_height="wrap_content"></TextView>
        <EditText android:layout_height="wrap_content"
            android:layout_width="match_parent"
      android:id="@+id/etAction"></EditText>
        <TextView android:text="Hateful Outro"
     android:layout_width="wrap_content"
            android:layout_height="wrap_content"></TextView>
        <EditText android:layout_height="wrap_content"
            android:layout_width="match_parent" 
   android:id="@+id/etOutro"></EditText>
    </LinearLayout>

 </ScrollView>
 <LinearLayout android:orientation="vertical"
    android:layout_width="match_parent" android:layout_weight="40"
    android:layout_height="fill_parent">
    <Button android:text="Send Email" android:id="@+id/bSentEmail"
        android:layout_width="fill_parent" 
 android:layout_height="fill_parent"></Button>
 </LinearLayout>
 <LinearLayout android:orientation="vertical"
    android:layout_width="match_parent" android:layout_weight="30"
    android:layout_height="fill_parent">
    <AnalogClock android:id="@+id/analogClock1"
        android:layout_width="fill_parent"
 android:layout_height="fill_parent"></AnalogClock>
 </LinearLayout>

  </LinearLayout>

here a runtime exception occured as

987-1987/com.example.shubham.myapplication E/AndroidRuntime﹕ FATAL EXCEPTION: main Process: com.example.shubham.myapplication, PID: 1987 android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.SEND flg=0x1 (has clip) (has extras) }

1 Answers1

0

Make sure you have any email application installed on the mobile device you are testing on and

replace

 ourIntent.putExtra(Intent.EXTRA_TEXT,message);

with

ourIntent.putExtra(android.content.Intent.EXTRA_TEXT, Html.fromHtml(message);

Same problem has been answered here.

Community
  • 1
  • 1
Jitender Dev
  • 6,907
  • 2
  • 24
  • 35