Reputation: 1591
I have made a simple Emailsending demo in android for the learning purpose,I have reffred it from the Link below: enter link description here
every thing is working fine,But the thing is when i click on "send" button of the application,I shows"No application can perform this task"....in place of showing exixsting email clients of emulator..So can anyone please tell me how can i call email client in my program?
my code is:
main.java
package com.example.emaildemo;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity extends Activity {
Button send;
EditText to,sub,msg;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
send=(Button)findViewById(R.id.Send);
to=(EditText)findViewById(R.id.to);
sub=(EditText)findViewById(R.id.subject);
msg=(EditText)findViewById(R.id.message);
send.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
String s1=to.getText().toString();
String s2=sub.getText().toString();
String s3=msg.getText().toString();
Intent i =new Intent(Intent.ACTION_SEND);
i.putExtra(Intent.EXTRA_EMAIL, new String[]{s1});
i.putExtra(Intent.EXTRA_SUBJECT, new String[]{s2});
i.putExtra(Intent.EXTRA_TEXT, new String[] {s3});
i.setType("message/rfc822");
startActivity(Intent.createChooser(i, "Choose an Email client :"));
}
});
}
}
Upvotes: 0
Views: 147
Reputation: 1591
By running the program on real device it will automatically call the existing email clients of your device..!
Upvotes: 0
Reputation: 5472
Run & test on real device only.
If you run this on emulator, you will hit error message : “No application can perform this action“. This code only work on real device.
Upvotes: 1