How can ImageView link to a email? - android

Is it possible to make an imageview link to the email app? Like when you click it the email app will open with a specific email address to send?

findViewById(R.id.imageview).setOnClickListener(new OnClickListener() {
public void onClick(View _) {
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.fromParts("mailto","abc#gmail.com", null));
startActivity(i);
}
}

img.setOnClickListener(
new OnClickListener(View v) {
String yourMail = "mail#example.com";
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("message/rfc822");
intent.putExtra(Intent.EXTRA_EMAIL, new String[]{yourMail});
intent.putExtra(Intent.EXTRA_SUBJECT, "Your subject");
intent.putExtra(Intent.EXTRA_TEXT, "Your content");
try {
startActivity(intent, "Pick an email application...");
} catch(Exception e) {
Toast.makeText(YourMainActivity.this, "Have no email application!", Toast.LENGTH_SHORT).show();
}
}
);

Related

Send URL/link with custom scheme through WhatsApp

I have a requirement of sending a url(myapp://app.myapp.com/data)with custom scheme through WhatsApp.But in WhatsApp its not showing custom scheme(myapp://) as link. Only app.myapp.com/data is showing as link.
I have tried below code:
Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_TEXT,"Please check this link: "+Html.fromHtml("myapp://app.myapp.com/data"));
intent.setType("text/plain");
startActivity(Intent.createChooser(intent, "Select Chooser to send friend"));
Is it possible to send link with custom scheme on WhatsApp in android platform?
try this code:
Whatsappbutton.setOnClickListener(new OnClickListener() {
#SuppressLint("NewApi") #Override
public void onClick(View v) {
// TODO Auto-generated method stub
try {
Tracker t = ((Analytics) getActivity().getApplication())
.getTracker(TrackerName.APP_TRACKER);
t.send(new HitBuilders.EventBuilder()
.setCategory(getString(R.string.ic_Category))
.setAction(getString(R.string.ic_action))
.setLabel(getString(R.string.ic_labelwhatsapp)).build());
} catch (Exception e) {
Toast.makeText(getActivity().getApplicationContext(),
"Error" + e.getMessage(), 1).show();
}
Toast.makeText(getActivity(), R.string.invite_friends_toast_after_share, Toast.LENGTH_LONG).show();
final String shareBody = getResources().getString(R.string.invite_friends_market_url);
try {
Intent shareToWhatsApp = new Intent(Intent.ACTION_SEND);
shareToWhatsApp.setType("text/plain");
shareToWhatsApp.putExtra(android.content.Intent.EXTRA_TEXT,
shareBody);
shareToWhatsApp.setClassName("com.whatsapp",
"com.whatsapp.ContactPicker");
startActivity(shareToWhatsApp);
} catch (Exception e) {
Intent shareGeneric = new Intent(Intent.ACTION_SEND);
shareGeneric.setType("text/plain");
shareGeneric.putExtra(android.content.Intent.EXTRA_TEXT,
shareBody);
startActivity(Intent.createChooser(shareGeneric,
getResources().getString(R.string.invite_friends_share_chooser)));
}
}
});

How can I share text in what's app on particular Number

Using this code only open particulat number's chat but Text is not share.How can I do this?
public class MainActivity extends AppCompatActivity {
Button Wa;
String id = "+919000000000";
EditText txt;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
txt = (EditText)findViewById(R.id.editText);
Wa = (Button)findViewById(R.id.btn_whatsapp);
Wa.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Uri uri = Uri.parse("smsto:" + id);
Intent waIntent = new Intent(Intent.ACTION_SENDTO,uri);
String text = "testing message";
waIntent.setPackage("com.whatsapp");
if (waIntent != null) {
waIntent.putExtra(Intent.EXTRA_TEXT, text);
startActivity(Intent.createChooser(waIntent, text));
} else {
Toast.makeText(getApplicationContext(), "WhatsApp not found", Toast.LENGTH_SHORT)
.show();
}
}
});
}
Since you trying to achieve it as "smsto:", "text/plain" as type will help you. Try Extra as "sms_body" if it won't help.
Uri uri = Uri.parse("smsto:" + id);
Intent waIntent = new Intent(Intent.ACTION_SENDTO,uri);
String text = "testing message";
waIntent.setPackage("com.whatsapp");
if (waIntent != null) {
waIntent.setType("text/plain");
//waIntent.putExtra(Intent.EXTRA_TEXT, text);
waIntent.putExtra("sms_body", text);
startActivity(Intent.createChooser(waIntent, text));
} else {
Toast.makeText(getApplicationContext(), "WhatsApp not found", Toast.LENGTH_SHORT)
.show();
}
Please go through this stackoverflow links
Sending message through WhatsApp
Send text to specific contact
It seems that WhatsApp still does't have supported this fetaure.
You can only open chat history for particular number using below code
try {
Uri mUri = Uri.parse("smsto:+98xxxxxxxx");
Intent mIntent = new Intent(Intent.ACTION_SENDTO, mUri);
mIntent.setPackage("com.whatsapp");
// mIntent.putExtra("sms_body", "My body");
mIntent.putExtra(Intent.EXTRA_TEXT, "This is my text to send.");
startActivity(mIntent);
} catch (Exception e) {
// alert WhatsApp in not installed
}
Answer from Here
Earlier it wasn't possible but since the May '15 update. Checkout :
try{
PackageInfo info = pm.getPackageInfo("com.whatsapp", PackageManager.GET_META_DATA);
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
String sendString = "some random string";
sendIntent.setPackage("com.whatsapp");
sendIntent.putExtra(Intent.EXTRA_TEXT, sendString);
sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
sendIntent.setType("image/*");
startActivity(sendIntent);
} catch (Exception e){
// some code
}
Here PackageInfo line is just to check if WhatsApp is installed. It throws Exception if not. You can just ignore that if you want to do a normal share (and setPackage also).
Also. It is important that the media you want to share has to be publicly available on local storage.
UPDATE
To send to a specific contact
Uri uri = Uri.parse("smsto:" + "<CONTACT_NUMBER>");
Intent i = new Intent(Intent.ACTION_SENDTO, uri);
i.putExtra(Intent.EXTRA_TEXT, whatsAppMessage);
As Action Send To is now allowed.
Try something like this:
public class MainActivity extends AppCompatActivity {
Button Wa;
String id = "+919000000000";
EditText txt;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
txt = (EditText)findViewById(R.id.editText);
Wa = (Button)findViewById(R.id.btn_whatsapp);
Wa.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
PackageManager pm=getPackageManager();
try {
Uri uri = Uri.parse("smsto:" + number);
Intent i = new Intent(Intent.ACTION_SENDTO, uri);
waIntent.setType("text/plain");
String text = "testing message";
PackageInfo info=pm.getPackageInfo("com.whatsapp", PackageManager.GET_META_DATA);
waIntent.setPackage("com.whatsapp");
waIntent.putExtra(Intent.EXTRA_TEXT, text);
startActivity(Intent.createChooser(waIntent, text));
}
catch (NameNotFoundException e) {
Toast.makeText(this, "WhatsApp not found", Toast.LENGTH_SHORT).show();
}
}
});
}
}

Android email attachment missing

I was trying to send an email with image as attachment.I see the item attached to the mail while sending , but in the inbox i see just the mail message but attachment missing. Please help me if my code went wrong somewhere
ArrayList<String> fetchList= new ArrayList<>();
fetchList= getIntent().getStringArrayListExtra("Uri");
ArrayList<Uri> uriList=new ArrayList<>();
for (int i=0;i<fetchList.size();i++){
uriList.add(i,Uri.parse(fetchList.get(i)));
}
public void sendClicked(View view) {
String emailBody =textMessage.getText().toString();
String emailSubject=textSubject.getText().toString();
String Email_To[]=new String[]{"kittutanu#yahoo.co.in"};
final Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_EMAIL, Email_To);
intent.putExtra(Intent.EXTRA_SUBJECT, emailSubject);
intent.putExtra(Intent.EXTRA_TEXT, emailBody);
if (uriList != null) {
intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uriList);
}
try {
this.startActivity(intent);
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
}
}
}
Have you tried with multipart/alternative or multipart/mixed type?
Here is an example How to send an email with a file attachment in Android

How to share text on whatsapp in android?

I am using a button in a listview and want to share text on whatsapp...here is my code...this code is working without taking a listview...but i making a project in which i am using a listview.....
Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, "Try this : https://play.google.com/store/apps/details?id=com.listviewexample");
startActivity(Intent.createChooser(intent, "Share via"));
Try this
public void onClickWhatsApp(View view) {
Intent waIntent = new Intent(Intent.ACTION_SEND);
waIntent.setType("text/plain");
String text = "Try this : https://play.google.com/store/apps/details?id=com.listviewexample";
waIntent.setPackage("com.whatsapp");
if (waIntent != null) {
waIntent.putExtra(Intent.EXTRA_TEXT, text);//
startActivity(Intent.createChooser(waIntent, "Share with"));
} else {
Toast.makeText(this, "WhatsApp not Installed", Toast.LENGTH_SHORT).show();
}
}

Can't add email signature in Android

I'm trying to compose and send an email which will include a signature at the bottom
of my email content in android. I'm able to send an email but I'm not getting the way that allows me to add my own signature. Do you have any suggestion?
here's my code:
public void addListener() {
final Button button = (Button) findViewById(R.id.button1);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
findViewById = (TextView) findViewById(R.id.t1);
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("text/plain");
i.putExtra(Intent.EXTRA_EMAIL,
new String[] { "some#gmail.com"});
/*i.putExtra(Intent.EXTRA_CC,
new String[] { "some#gmail.com" });*/
i.putExtra(Intent.EXTRA_SUBJECT, "Android Test");
i.putExtra(Intent.EXTRA_TEXT, "Body");
//i.putExtra(Intent.EXTRA_TEXT, "signature");
try {
startActivity(Intent.createChooser(i, "Choose mail app..."));
} catch (android.content.ActivityNotFoundException ex) {
}
}
});
}
I don't think the "signature" is really a different section of an email. I think you can just append your signature to your body.
i.putExtra(Intent.EXTRA_TEXT, "Body" + "\\n" + "Signature");

Categories

Resources