I am invoking a mail intent in
ImageButton mail=(ImageButton)findViewById(R.id.mailgps);
mail.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
setContentView(R.layout.mail);
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
// TODO Auto-generated method stub
emailIntent.setType("text/plain");
String emailto[]={"myemail"};
String subject="GPS User Report";
String body="Welcome to Samarth Reporting service.Did you see an untracked Dustbin\n.A dustbin not at the right place??\nWant to suggest placement of a dustbin here.\nGo ahead we are all ears.\n.Your present location is\n Latitude: ";
body=body + "28.67890" + " and Longitudes: " + "79.78965";
body=body + "\n\nTell us more.";
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,emailto);
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,subject);
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,body);
startActivity(emailIntent);
}
});
and getting the screen like this which ignores the EXTRA_EMAIL attribute as well as EXTRA_SUBJECT and then the body appears at the very bottom.How can I rectify this.??
Well it was a pretty stupid thing.
As earlier I was using another AVD I had the email client setup so it worked nicely.But on the new AVD I overlooked that.So "first" setup the email client then go for invoking intent.
Nonetheless the system should have a better way of handling such situations rather than showing a weird blank screen.
Related
I have a share button in my application, whose purpose is to share a string of information with user selected app (for example twitter or gmail). The problem is when you click the share button, the share window appears and the app becomes black in the background. After done sharing, the user is returned to menu / home screen and has to open the app again in order to continue using it from where they left.
What I need is to go back to my app after done sharing.
This is the OnClickListener I used:
shareButton.setOnClickListener(
new View.OnClickListener() {
#Override
public void onClick(View view) {
String text = mContext.getString(R.string.shareText) + " " + profileInfo.getName() + " " + mContext.getString(R.string.shareText2);
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_TEXT, text);
shareIntent.setType("text/plain");
startActivity(shareIntent);
}
}
);
What am I doing wrong here? Any help is appreciated.
Use startActivityForResult() instead of startActivity(). This will return to the starting Activity after the Intent action is completed. See the Getting a Result from an Activity post for an example.
And wait for response by overriding onActivityResult() method :
#Override public void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub if(requestCode == 0) {
// You will get callback here when email activity is exited
// perform you task here
}
There is noting wrong with your share intent code which you mentioned above, although there could be some thing wrong with your onPause() method, you probably doing some thing there, try to debug the code after adding logs So you can track the issue OR put your activity code here So exact issue can be identified.
I am trying to have it so that when the phone number is clicked, it makes a call. The phone number is displaying correctly, but nothing happens when I click it.
Why is this not working?
tvInfo.setText(Html.fromHtml("<a href='tel:15555555555'><b>(555) 555-5555</b></a>"));
Let me know if more information is needed. Thanks!
Try looking at Linkify. Set the phone number normally with setText, and then use Linkify.
tvInfo.setText("(555)555-5555");
Linkify.addLinks(tvInfo, Linkify.PHONE_NUMBERS);
Try this:
call.setText(Html.fromHtml("<u>" + "9999999999" + "</u>"));
call.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
number = call.getText().toString();
Intent intent = new Intent(Intent.ACTION_DIAL);
intent.setData(Uri.parse("tel:" + number));
startActivity(intent);
}
});
I need a little help.
I have ,in my app, a textView which contains a phone number,and i want to make a call when i click that phone number.
I've already accomplished that:
sitePhone.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
String number = "tel:" + sitePhone.getText().toString().trim();
Intent callIntent = new Intent(Intent.ACTION_CALL, Uri.parse(number));
startActivity(callIntent);
}
});
Now the problem is that sometimes i have on my text view 2 or 3 phone numbers.Something like this: "07456443345 FAR: 0745456334".I take the phone number string from the database so it cannot be altered.
Any ides of how i can make a call on each number click? thanks in advance
i found a simple answer:
android:autoLink="phone" will to the trick.
I have some text in my application that says in case you need extra help, please email us and here is the email address, blah, blah.
But I want them to be able to click the email link and have their email client open. Is that possible? Or is that bad practice?
If it is reasonable practice, how can it be done?
This is a very reasonable request and the Linkify class will turn every email address into an appropriate link for you. Simply add the autoLink attribute to your XML:
<TextView
...
android:autoLink="email" />
You can make your text clickable by using setOnClickListener on the text
textView.setOnClickListener(new View.OnClickListener());
You can open the email client by creating a new Intent with the ACTION_SEND. Settype, the email address and subject like this:
Intent emailintent = new Intent(android.content.Intent.ACTION_SEND);
emailintent.setType("plain/text");
emailintent.putExtra(android.content.Intent.EXTRA_EMAIL,new String[] {"mailk#gmail.com" });
emailintent.putExtra(android.content.Intent.EXTRA_SUBJECT, "");
emailintent.putExtra(android.content.Intent.EXTRA_TEXT,"");
startActivity(Intent.createChooser(emailintent, "Send mail..."));
You need to fire an intent in your onClickListener:
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain"); // send email as 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, ""));
Please be aware of a little bug from API 24 onwards which makes the accepted solution not work if the local part of the email address has exactly 2 characters like "it#google.com".
See the issue: https://issuetracker.google.com/issues/64435698
Allegedly fixed already, but apparently not rolled out yet.
(Don't you love it that they know about the issue and don't even bother to update the documentation accordingly? https://developer.android.com/reference/android/widget/TextView.html#attr_android:autoLink)
So unless you're sure that you're not dealing with such 2-letter email addresses, you should rather use the accepted approach from here for the time being:
TextView to send email when clicked
Take care to remove the autolink attribute from the TextView then.
The accepted answer may work for emails but if you want to detect different patterns like emails, contact numbers, weblink and set a separate on click implementations for these patterns I suggest you to use CustomClickableEmailPhoneTextview
Sample Code to use the library.
CustomPartialyClickableTextview customPartialyClickableTextview= (CustomPartialyClickableTextview) findViewById(R.id.textViewCustom);
/**
* Create Objects For Click Patterns
*/
ClickPattern email=new ClickPattern();
ClickPattern phone=new ClickPattern();
ClickPattern weblink=new ClickPattern();
/**
* set Functionality for what will happen on click of that pattern
* In this example pattern is email
*/
email.setOnClickListener(new ClickPattern.OnClickListener() {
#Override
public void onClick() {
Toast.makeText(MainActivity.this,"email clicked",Toast.LENGTH_LONG).show();
}
});
/**
* set Functionality for what will happen on click of that pattern
* In this example pattern is phone
*/
phone.setOnClickListener(new ClickPattern.OnClickListener() {
#Override
public void onClick() {
Toast.makeText(MainActivity.this,"phone clicked",Toast.LENGTH_LONG).show();
}
});
/**
* set Functionality for what will happen on click of that pattern
* In this example pattern is weblink
*/
weblink.setOnClickListener(new ClickPattern.OnClickListener() {
#Override
public void onClick() {
Toast.makeText(MainActivity.this,"website clicked",Toast.LENGTH_LONG).show();
}
});
/**
* set respective regex string to be used to identify patter
*/
email.setRegex("\\b[A-Z0-9._%+-]+#[A-Z0-9.-]+\\.[A-Z]{2,4}\\b"); // regex for email
phone.setRegex("[1-9][0-9]{9,14}"); // regex for phone number
weblink.setRegex("^(https?|ftp|file)://[-a-zA-Z0-9+&##/%?=~_|!:,.;]*[-a-zA-Z0-9+&##/%=~_|]"); // regex for weblink
/**
* add click pattern to the custom textview - first parameter is tag for reference second parameter is ClickPattern object
*/
customPartialyClickableTextview.addClickPattern("email",email);
customPartialyClickableTextview.addClickPattern("phone",phone);
customPartialyClickableTextview.addClickPattern("weblink",weblink);
eTSubject = (EditText) findViewById(R.id.eTSubject);
eTContent = (EditText) findViewById(R.id.eTContent);
subject = eTSubject.getText().toString();
content = eTContent.getText().toString();
iBMail.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
i = new Intent(android.content.Intent.ACTION_SEND);
i.setType("plain/text");
i.putExtra(android.content.Intent.EXTRA_EMAIL,
new String[] { "" });
i.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
i.putExtra(android.content.Intent.EXTRA_TEXT, content);
startActivity(Intent.createChooser(i, "Continue with send?"));
}
});
Above is my piece of code, which is trying to send email with some text i'm tryin to put in email screen and amazingly not getting that content when email screen is opening. Anyone have any idea why is it not working?
Any help will highly be appreciated.
mrana..
Guys i have solved this issue. If any of you are facing such kinda issue then all you have to do is to put your string variable where you are getting the text and changing the edittext into string within your click method which you are triggering from the view by pressing any widget.