I have an image already chosen and in an image view but now I would like to send the same image using a send button.How can I fetch the image so that if one clicks on the send button it choses the image and gives him a variety of options in how he can send the image.
Send button code is below
Button buttonSendImage = (Button) findViewById(R.id.button2);
buttonSendImage.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent picMessageIntent = new Intent(android.content.Intent.ACTION_SEND);
picMessageIntent.setType("image/jpeg");
startActivity(Intent.createChooser(picMessageIntent, "Send your picture using:"));
}
});Button buttonSendImage = (Button) findViewById(R.id.button2);
buttonSendImage.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent picMessageIntent = new Intent(android.content.Intent.ACTION_SEND);
picMessageIntent.setType("image/jpeg");
startActivity(Intent.createChooser(picMessageIntent, "Send your picture using:"));
}
});
if my understanding is correct, You can use the following code :
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
// Add your image URI here and send in a button click.
shareIntent.putExtra(Intent.EXTRA_STREAM, uriToImage);
shareIntent.setType("image/jpeg");
startActivity(Intent.createChooser(shareIntent, getResources().getText(R.string.send_to)));
You can use a MIME type of "*/*"
Related
This is the code for the share button. The thing is, sharing is not working when pressed the send button
viewHolder.ivSend.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
StringBuilder dataString = new StringBuilder();
int song = music.getSong();
dataString.append("Song :"+ song + "\n");
Uri uri = Uri.parse(dataString.toString());
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("audio/mp3");
share.putExtra(Intent.EXTRA_STREAM, uri);
context.startActivity(Intent.createChooser(share, "Share Sound File"));
}
});
This question already has answers here:
Sending Email in Android using JavaMail API without using the default/built-in app
(25 answers)
Closed 6 years ago.
I've a feedback form and buttons for send and cancel. How can I make the feedback send responds to a default email when the send button is clicked? And how can I set a the default email. Is this possible? Please let me know. Thank you.
Here's is my java for the feedback form :
#Override
public void onClick(View arg0) {
// Create custom dialog object
final Dialog dialog = new Dialog(MainActivity.this);
// Include dialog.xml file
dialog.setContentView(R.layout.activity_main);
// Set dialog title
dialog.setTitle("Feedback");
dialog.show();
Button button1 = (Button) dialog.findViewById(R.id.button1);
// if decline button is clicked, close the custom dialog
button1.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// Close dialog
dialog.dismiss();
}
});
Button button2 = (Button) dialog.findViewById(R.id.button2);
// if decline button is clicked, close the custom dialog
button2.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// Close dialog
dialog.dismiss();
}
});
Open your email client programatically using a chooser:
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("plain/text");
intent.putExtra(Intent.EXTRA_EMAIL, new String[] { "some#email.address" });
intent.putExtra(Intent.EXTRA_SUBJECT, "subject");
intent.putExtra(Intent.EXTRA_TEXT, "mail body");
startActivity(Intent.createChooser(intent, ""));
To send email programatically without using chooser,you can use this link.
You can use following snippet:
private void sendEmail(String email) {
Intent emailIntent = new Intent(Intent.ACTION_SENDTO);
String aEmailList[] = {email};
emailIntent.setData(Uri.parse("mailto:")); // only email apps should handle this
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, aEmailList);
String feedback_msg = getString(R.string.feedback_msg);
emailIntent.putExtra(Intent.EXTRA_TEXT, Html.fromHtml("<i><font color='your color'>" + feedback_msg + "</font></i>"));
emailIntent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.feedback_msg));
PackageManager packageManager = getActivity().getPackageManager();
boolean isIntentSafe = emailIntent.resolveActivity(packageManager) != null;
if (isIntentSafe) {
startActivity(emailIntent);
} else {
Toast.makeText(getActivity(), R.string.email_app_not_installed, Toast.LENGTH_SHORT).show();
}
}
}
The app has 2 buttons on the screen, 1 for taking a photo and attaching it on the screen and the second to attach the photo on gmail & send it to someone. I'm using this code for the second button
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts(
"mailto", "test#gmail.com", null));
intent.putExtra(Intent.EXTRA_SUBJECT, "test");
intent.putExtra(Intent.EXTRA_TEXT, "text");
intent.putExtra(Intent.EXTRA_STREAM, imageUri);
startActivity(Intent.createChooser(intent, "Choose an Email client :"));
}
But it doesn't attach the photo on gmail. It might be wrong. Here's the rest of the code.
public class MainActivity extends Activity {
private static int TAKE_PICTURE = 1;
private Uri imageUri;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button sendbutton = (Button) findViewById(R.id.sendbutton);
sendbutton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts(
"mailto", "test#gmail.com", null));
intent.putExtra(Intent.EXTRA_SUBJECT, "test");
intent.putExtra(Intent.EXTRA_TEXT, "text");
intent.putExtra(Intent.EXTRA_STREAM, imageUri);
startActivity(Intent.createChooser(intent,
"Choose an Email client :"));
}
});
Button cameraButton = (Button) findViewById(R.id.button_camera);
cameraButton.setOnClickListener(cameraListener);
}
private OnClickListener cameraListener = new OnClickListener() {
public void onClick(View v) {
takePhoto(v);
}
};
public void takePhoto(View v) {
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
File photo = new File(
Environment
.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES),
"pic.jpg");
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photo));
imageUri = Uri.fromFile(photo);
startActivityForResult(intent, TAKE_PICTURE);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case 1:
if (resultCode == Activity.RESULT_OK) {
Uri selectedImage = imageUri;
getContentResolver().notifyChange(selectedImage, null);
ImageView imageView = (ImageView) findViewById(R.id.image_view_camera);
ContentResolver cr = getContentResolver();
Bitmap bitmap;
try {
bitmap = android.provider.MediaStore.Images.Media
.getBitmap(cr, selectedImage);
imageView.setImageBitmap(bitmap);
Toast.makeText(MainActivity.this, selectedImage.toString(),
Toast.LENGTH_LONG).show();
} catch (Exception e) {
Toast.makeText(MainActivity.this, "failed to load",
Toast.LENGTH_LONG).show();
}
}
}
}
}
Try this
You can see more at this link: Sharing content in android using action send intent
public void onClick(View v) {
// TODO Auto-generated method stub
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setType("image/png");
sharingIntent.putExtra(Intent.EXTRA_SUBJECT, "test");
sharingIntent.putExtra(Intent.EXTRA_TEXT, "text");
sharingIntent.putExtra(Intent.EXTRA_STREAM, targetUri);
startActivity(Intent.createChooser(sharingIntent, "Share image using"));
}
Hi friends,
I need to send zip file as attachment to email. I have tried using code below. However, I receive email message without the attachment. What am I doing wrong?
public class MainActivity extends Activity {
Button email;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
email=(Button)findViewById(R.id.button1);
email.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_EMAIL, new String[]{"radha#impressol.com"});
intent.putExtra(Intent.EXTRA_SUBJECT, "Email Subject");
intent.putExtra(Intent.EXTRA_TEXT, "Email Message");
intent.setType("application/zip");
intent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://+/sdcard/zipname.zip"));
startActivity(Intent.createChooser(intent, "Send Email"));
}
});
}
}
In your case remove the "+" from Uri string.
P.S. it'll also work without Uri protocol, like (Environment.getExternalStorageDirectory()+"/zipname.zip");
public class AndroidEmailActivity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final EditText edittextEmailAddress = (EditText) findViewById(R.id.email_address);
final EditText edittextEmailSubject = (EditText) findViewById(R.id.email_subject);
final EditText edittextEmailText = (EditText) findViewById(R.id.email_text);
Button buttonSendEmail_intent = (Button) findViewById(R.id.sendemail_intent);
buttonSendEmail_intent.setOnClickListener(new Button.OnClickListener() {
#Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
String emailAddress = edittextEmailAddress.getText().toString();
String emailSubject = edittextEmailSubject.getText().toString();
String emailText = edittextEmailText.getText().toString();
String emailAddressList[] = { emailAddress };
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("plain/text");
intent.putExtra(Intent.EXTRA_EMAIL, emailAddressList);
intent.putExtra(Intent.EXTRA_SUBJECT, emailSubject);
intent.putExtra(Intent.EXTRA_TEXT, emailText);
startActivity(Intent.createChooser(intent,
"Choice App t send email:"));
}
});
}
}
This is my code.I am not getting any emails.I need to send emails through this intent method.how can I acheive that?Where I went wrong?pls give some suggestions.
I am getting the error when I click the Send email button as "No applications can perform this action."
This is my code to send emails:
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_SUBJECT, activity.getString(R.string.share_email_subject));
sendIntent.setType("message/rfc822");
activity.startActivity(Intent.createChooser(sendIntent, "Choose Email Client"));
Try removing the plain/text type?
It is Good practice to work with original device rather than on Virtual Device. I suggest you try this code block on real device.
Intent sendEmail= new Intent(Intent.ACTION_SEND);
sendEmail.setType("plain/text");
startActivity(Intent.createChooser(sendEmail, "Email:"));
If you want to see more on Email with Intent then refer to this post:
http://androidtutforbeginner.blogspot.com/2012/03/send-email-with-intent-in-android.html