Android email no search

How to get the Android device’s primary e-mail address

How do you get the Android’s primary e-mail address (or a list of e-mail addresses)?

It’s my understanding that on OS 2.0+ there’s support for multiple e-mail addresses, but below 2.0 you can only have one e-mail address per device.

13 Answers 13

There are several ways to do this, shown below.

As a friendly warning, be careful and up-front to the user when dealing with account, profile, and contact data. If you misuse a user’s email address or other personal information, bad things can happen.

Method A: Use AccountManager (API level 5+)

You can use AccountManager.getAccounts or AccountManager.getAccountsByType to get a list of all account names on the device. Fortunately, for certain account types (including com.google ), the account names are email addresses. Example snippet below.

Note that this requires the GET_ACCOUNTS permission:

More on using AccountManager can be found at the Contact Manager sample code in the SDK.

Method B: Use ContactsContract.Profile (API level 14+)

As of Android 4.0 (Ice Cream Sandwich), you can get the user’s email addresses by accessing their profile. Accessing the user profile is a bit heavyweight as it requires two permissions (more on that below), but email addresses are fairly sensitive pieces of data, so this is the price of admission.

Below is a full example that uses a CursorLoader to retrieve profile data rows containing email addresses.

This requires both the READ_PROFILE and READ_CONTACTS permissions:

Источник

How to check edittext’s text is email address or not?

how to check the text of edittext is email address or not without using javascript and regular expression? Here I used inputtype=»textEmailAddress» this is working but no error message is display.

20 Answers 20

On Android 2.2+ use this:

Pass your edit text string in this function .

for right email verification you need server side authentication

Note there is now a built-in method in Android, see answers below.

Please follow the following Steps

I wrote a library that extends EditText which supports natively some validation methods and is actually very flexible.

Current, as I write, natively supported (through xml attributes) validation methods are:

  1. regexp: for custom regexp
  2. numeric: for an only numeric field
  3. alpha: for an alpha only field
  4. alphaNumeric: guess what?
  5. email: checks that the field is a valid email
  6. creditCard: checks that the field contains a valid credit card using Luhn Algorithm
  7. phone: checks that the field contains a valid phone number
  8. domainName: checks that field contains a valid domain name ( always passes the test in API Level

Источник

Sending Email in Android using JavaMail API without using the default/built-in app

I am trying to create a mail sending application in Android.

This will launch the built-in Android application; I’m trying to send the mail on button click directly without using this application.

25 Answers 25

Send e-mail in Android using the JavaMail API using Gmail authentication.

Steps to create a sample Project:

MailSenderActivity.java:

GMailSender.java:

JSSEProvider.java:

ADD 3 jars found in the following link to your Android Project

And don’t forget to add this line in your manifest:

Just click below link to change account access for less secure apps https://www.google.com/settings/security/lesssecureapps

Run the project and check your recipient mail account for the mail. Cheers!

P.S. And don’t forget that you cannot do network operation from any Activity in android. Hence it is recommended to use AsyncTask or IntentService to avoid network on main thread exception.

Thank you for your valuable information. Code is working fine. I am able to add attachment also by adding following code.

Could not connect to SMTP host: smtp.gmail.com, port: 465

Add this line in your manifest:

You can use JavaMail API to handle your email tasks. JavaMail API is available in JavaEE package and its jar is available for download. Sadly it cannot be used directly in an Android application since it uses AWT components which are completely incompatible in Android.

You can find the Android port for JavaMail at the following location: http://code.google.com/p/javamail-android/

Add the jars to your application and use the SMTP method

100% working code with demo You can also send multiple emails using this answer.

Download Project HERE

Step 1: Download mail, activation, additional jar files and add in your project libs folder in android studio. I added a screenshot see below Download link

Login with gmail (using your from mail) and TURN ON toggle button LINK

Most of the people forget about this step i hope you will not.

Step 2 : After completing this process. Copy and past this classes into your project.

GMail.java

SendMailTask.java

Step 3 : Now you can change this class according to your needs also you can send multiple mail using this class. i provide xml and java file both.

activity_main.xml

SendMailActivity.java

Note Dont forget to add internet permission in your AndroidManifest.xml file

Hope it work if it not then just comment down below.

In order to help those getting a Network On Main Thread Exception with an SDK Target >9. This is using droopie’s code above but will work similarly for any.

You can use AsyncTask as below

Using SMTP is one way to go, and the others have already pointed out ways how to do it. Just note that while doing this, you completely circumvent the built in mail app, and you will have to provide the address of the SMTP server, the user name and password for that server, either statically in your code, or query it from the user.

Another way would involve a simple server side script, like php, that takes some URL parameters and uses them to send a mail. This way, you only need to make an HTTP request from the device (easily possible with the built in libraries) and don’t need to store the SMTP login data on the device. This is one more indirection compared to direct SMTP usage, but because it’s so very easy to make HTTP request and send mails from PHP, it might even be simpler than the direct way.

Mail Application

If the mail shall be send from the users default mail account that he already registered with the phone, you’d have to take some other approach. If you have enough time and experience, you might want to check the source code of the Android Email application to see if it offers some entry point to send a mail without user interaction (I don’t know, but maybe there is one).

Maybe you even find a way to query the users account details (so you can use them for SMTP), though I highly doubt that this is possible, because it would be a huge security risk and Android is built rather securely.

Источник

How should I validate an e-mail address?

What’s a good technique for validating an e-mail address (e.g. from a user input field) in Android? org.apache.commons.validator.routines.EmailValidator doesn’t seem to be available. Are there any other libraries doing this which are included in Android already or would I have to use RegExp?

36 Answers 36

Another option is the built in Patterns starting with API Level 8:

OR

One line solution from @AdamvandenHoven:

Next pattern is used in K-9 mail:

You can use function

Since API 8 (android 2.2) there is a pattern: android.util.Patterns.EMAIL_ADDRESS http://developer.android.com/reference/android/util/Patterns.html

So you can use it to validate yourEmailString:

returns true if the email is valid

UPD: This pattern source code is:

So you can build it yourself for compatibility with API

We have a simple Email pattern matcher now.

Java:

Kotlin Function:

Kotlin Extension:

Don’t use a reg-ex.

Apparently the following is a reg-ex that correctly validates most e-mails addresses that conform to RFC 2822, (and will still fail on things like «user@gmail.com.nospam», as will org.apache.commons.validator.routines.EmailValidator)

Possibly the easiest way to validate an e-mail to just send a confirmation e-mail to the address provided and it it bounces then it’s not valid.

If you want to perform some basic checks you could just check that it’s in the form *@*

If you have some business logic specific validation then you could perform that using a regex, e.g. must be a gmail.com account or something.

Use simple one line code for email Validation

You could write a Kotlin extension like this:

And then call it like this:

This is Android Studio suggestions:

You can use regular expression to do so. Something like the following.

Note: Check the regular expression given above, don’t use it as it is.

use android:inputType=»textEmailAddress» as below:

There is a Patterns class in package android.util which is beneficial here. Below is the method I always use for validating email and many other stuffs

Simplest Kotlin solution using extension functions:

and then you can validate like this:

If you are in kotlin-multiplatform without access to Pattern , this is the equivalent:

Call This Method where you want to validate email ID.

For an Email validation android provide some InBuilt Pattern.But it only support API level 8 and above.

Here is code for use that pattern to check email validation.

Make sure that after execute this method you should check that if this method return true then you allow to save email and if this method return false then display message that email is «Invalid».

Hope you get your answer, Thanks you.

Can I STRONGLY recommend you don’t try to ‘validate’ email addresses, you’ll just get yourself into a lot of work for no good reason.

Just make sure what is entered won’t break your own code — e.g. no spaces or illegal characters which might cause an Exception.

Anything else will just cause you a lot of work for minimal return.

Validate your email address format. Ex-virag@gmail.com

this is the best way in kotlin Useing Extension Function

If you are using API 8 or above, you can use the readily available Patterns class to validate email. Sample code:

By chance if you are even supporting API level less than 8, then you can simply copy the Patterns.java file into your project and reference it. You can get the source code for Patterns.java from this link

Here is android.util.Patterns.EMAIL_ADDRESS

String will match it if

Example some special match email

You may modify this pattern for your case then validate by

Try this simple method which can not accept the email address beginning with digits:

Try this code.. Its really works..

Following was used by me. However it contains extra characters than normal emails but this was a requirement for me.

]+ Atleast one characters defined. («\» is used for escaping).

  • @ There might be one «@».
  • [A-Za-z0-9]+ then atleast one character defined.
  • [A-Za-z0-9-.]* Zero or any repetition of character defined.
  • [A-Za-z0-9]+ Atleast one char after dot.
  • The key here is that you want to fully validate the email address. You don’t just want to check it for syntactic correctness, you want to check whether the email address is real.

    Two obvious reasons: real users often mis-type their email addresses, and some users may put in fake email addresses. Therefore, you want to do a syntactic check and an existence check.

    The best way to do this that I have found on Android is to use the free Cloudmersive Validation API for this.

    The code looks like this:

    I’m using this in all my apps and it is great because I can validate the email addresses in the UX at the point of entry.

    Email Validation in Kotlin:

    This method is used for checking valid email id formats.

    Note that most of the regular expressions are not valid for international domain names (IDN) and new top level domains like .mobi or .info (if you check for country codes or .org, .com, .gov and so on).

    A valid check should separate the local part (before the at-sign) and the domain part. You should also consider the max length of the local part and domain (in sum 255 chars including the at-sign).

    The best approach is to transform the address in an IDN compatible format (if required), validate the local part (RFC), check the length of the address and the check the availability of the domain (DNS MX lookup) or simply send an email.

    Источник

    Читайте также:  Формат тиф для андроид
    Оцените статью