Java Code Examples for android.util.Patterns#EMAIL_ADDRESS

The following examples show how to use android.util.Patterns#EMAIL_ADDRESS . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VerifyOTP.java    From XERUNG with Apache License 2.0 6 votes vote down vote up
private ArrayList<String> getUserEmail(){

		ArrayList<String> email = new ArrayList<String>();

		Pattern emailPattern = Patterns.EMAIL_ADDRESS; // API level 8+
		Account[] accounts = AccountManager.get(VerifyOTP.this).getAccounts();
		for (Account account : accounts) {
			if (emailPattern.matcher(account.name).matches()) {
				String possibleEmail = account.name;
				if(possibleEmail != null)
					if(possibleEmail.length() !=0 ){
						email.add(possibleEmail);
					}
			}
		}		
		return email;

	}
 
Example 2
Source File: VerifyOTP.java    From XERUNG with Apache License 2.0 6 votes vote down vote up
private ArrayList<String> getUserEmail(){

		ArrayList<String> email = new ArrayList<String>();

		Pattern emailPattern = Patterns.EMAIL_ADDRESS; // API level 8+
		Account[] accounts = AccountManager.get(VerifyOTP.this).getAccounts();
		for (Account account : accounts) {
			if (emailPattern.matcher(account.name).matches()) {
				String possibleEmail = account.name;
				if(possibleEmail != null)
					if(possibleEmail.length() !=0 ){
						email.add(possibleEmail);
					}
			}
		}		
		return email;

	}
 
Example 3
Source File: EmailPlugin.java    From capacitor-email with MIT License 5 votes vote down vote up
@PluginMethod()
public void isAvailable(PluginCall call) {
    String app = call.getString("alias", "");
    boolean has = checkPermission();
    JSObject object = new JSObject();
    PackageManager pm = getActivity().getPackageManager();
    if (aliases.has(app)) {
        app = aliases.getString(app);
    }
    object.put("hasAccount", false);

    if (has) {
        AccountManager am;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            am = AccountManager.get(getContext());
        } else {
            am = AccountManager.get(getContext());
        }

        Pattern emailPattern = Patterns.EMAIL_ADDRESS;
        for (Account account : am.getAccounts()) {
            if (emailPattern.matcher(account.name).matches()) {
                object.put("hasAccount", true);
            }
        }

    }

    try {
        ApplicationInfo info = pm.getApplicationInfo(app, 0);
        object.put("hasApp", true);
    } catch (PackageManager.NameNotFoundException e) {
        object.put("hasApp", false);
    } finally {
        call.success(object);
    }

}
 
Example 4
Source File: BaseAuthFragment.java    From actor-platform with GNU Affero General Public License v3.0 5 votes vote down vote up
private String getSuggestedEmailChecked() {
    Pattern emailPattern = Patterns.EMAIL_ADDRESS;
    Account[] accounts = AccountManager.get(getActivity()).getAccounts();
    for (Account account : accounts) {
        if (emailPattern.matcher(account.name).matches()) {
            return account.name;
        }
    }

    return null;
}
 
Example 5
Source File: UserInfo.java    From echo with GNU General Public License v3.0 5 votes vote down vote up
public static String getUserEmail(Context c) {
    Pattern emailPattern = Patterns.EMAIL_ADDRESS; // API level 8+
    Account[] accounts = AccountManager.get(c).getAccounts();
    for (Account account : accounts) {
        if (emailPattern.matcher(account.name).matches()) {
            return account.name;
        }
    }
    return "";
}
 
Example 6
Source File: AccountUtil.java    From EmailAutoCompleteTextView with Apache License 2.0 5 votes vote down vote up
/**
 * Returns true if the given string is an email.
 */
private static boolean isEmail(String account) {

    if (TextUtils.isEmpty(account)) {
        return false;
    }

    final Pattern emailPattern = Patterns.EMAIL_ADDRESS;
    final Matcher matcher = emailPattern.matcher(account);
    return matcher.matches();
}
 
Example 7
Source File: ValidatorUtils.java    From Cangol-appcore with Apache License 2.0 5 votes vote down vote up
/**
 * 验证email地址格式是否正确
 *
 * @param str
 * @return
 */
public static boolean validateEmail(String str) {
    if (str == null || "".equals(str)) {
        return false;
    }
    final Pattern p = Patterns.EMAIL_ADDRESS;
    final Matcher m = p.matcher(str);
    return m.matches();
}
 
Example 8
Source File: IntentHelper.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Triggers a send email intent.  If no application has registered to receive these intents,
 * this will fail silently.
 *
 * @param context The context for issuing the intent.
 * @param email The email address to send to.
 * @param subject The subject of the email.
 * @param body The body of the email.
 * @param chooserTitle The title of the activity chooser.
 * @param fileToAttach The file name of the attachment.
 */
@CalledByNative
static void sendEmail(Context context, String email, String subject, String body,
        String chooserTitle, String fileToAttach) {
    Set<String> possibleEmails = new HashSet<String>();

    if (!TextUtils.isEmpty(email)) {
        possibleEmails.add(email);
    } else {
        Pattern emailPattern = Patterns.EMAIL_ADDRESS;
        Account[] accounts = AccountManager.get(context).getAccounts();
        for (Account account : accounts) {
            if (emailPattern.matcher(account.name).matches()) {
                possibleEmails.add(account.name);
            }
        }
    }

    Intent send = new Intent(Intent.ACTION_SEND);
    send.setType("message/rfc822");
    if (possibleEmails.size() != 0) {
        send.putExtra(Intent.EXTRA_EMAIL,
                possibleEmails.toArray(new String[possibleEmails.size()]));
    }
    send.putExtra(Intent.EXTRA_SUBJECT, subject);
    send.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(body));
    if (!TextUtils.isEmpty(fileToAttach)) {
        File fileIn = new File(fileToAttach);
        send.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(fileIn));
    }

    try {
        Intent chooser = Intent.createChooser(send, chooserTitle);
        // we start this activity outside the main activity.
        chooser.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(chooser);
    } catch (android.content.ActivityNotFoundException ex) {
        // If no app handles it, do nothing.
    }
}
 
Example 9
Source File: IntentHelper.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Triggers a send email intent.  If no application has registered to receive these intents,
 * this will fail silently.
 *
 * @param context The context for issuing the intent.
 * @param email The email address to send to.
 * @param subject The subject of the email.
 * @param body The body of the email.
 * @param chooserTitle The title of the activity chooser.
 * @param fileToAttach The file name of the attachment.
 */
@CalledByNative
static void sendEmail(Context context, String email, String subject, String body,
        String chooserTitle, String fileToAttach) {
    Set<String> possibleEmails = new HashSet<String>();

    if (!TextUtils.isEmpty(email)) {
        possibleEmails.add(email);
    } else {
        Pattern emailPattern = Patterns.EMAIL_ADDRESS;
        Account[] accounts = AccountManager.get(context).getAccounts();
        for (Account account : accounts) {
            if (emailPattern.matcher(account.name).matches()) {
                possibleEmails.add(account.name);
            }
        }
    }

    Intent send = new Intent(Intent.ACTION_SEND);
    send.setType("message/rfc822");
    if (possibleEmails.size() != 0) {
        send.putExtra(Intent.EXTRA_EMAIL,
                possibleEmails.toArray(new String[possibleEmails.size()]));
    }
    send.putExtra(Intent.EXTRA_SUBJECT, subject);
    send.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(body));
    if (!TextUtils.isEmpty(fileToAttach)) {
        File fileIn = new File(fileToAttach);
        send.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(fileIn));
    }

    try {
        Intent chooser = Intent.createChooser(send, chooserTitle);
        // we start this activity outside the main activity.
        chooser.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(chooser);
    } catch (android.content.ActivityNotFoundException ex) {
        // If no app handles it, do nothing.
    }
}
 
Example 10
Source File: CreateAccountFragment.java    From Linphone4Android with GNU General Public License v3.0 4 votes vote down vote up
private boolean isEmailCorrect(String email) {
	Pattern emailPattern = Patterns.EMAIL_ADDRESS;
	return emailPattern.matcher(email).matches();
}
 
Example 11
Source File: InAppPurchaseHelper.java    From Linphone4Android with GNU General Public License v3.0 4 votes vote down vote up
private boolean isEmailCorrect(String email) {
   	Pattern emailPattern = Patterns.EMAIL_ADDRESS;
   	return emailPattern.matcher(email).matches();
}
 
Example 12
Source File: FeedBackActivityFragment.java    From Cybernet-VPN with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onClick(View v)
{
    nameValue = name.getText().toString();
    emailvalue = email.getText().toString();
    phoneValue = phone.getText().toString();
    messageValue = message.getText().toString();

    Log.d("mylog",nameValue+messageValue);


    int flagName=0, flagEmail=0, flagMsg=0, flagPhone=0;

    Pattern emailPattern = Patterns.EMAIL_ADDRESS;
    Pattern phonePattern = Patterns.PHONE;

    boolean emailVal= emailPattern.matcher(emailvalue).matches();
    boolean phoneVal =phonePattern.matcher(phoneValue).matches();
    if(emailVal!=true)
    {
        email.setError("Invalid Email");
        flagEmail=0;
    }
    else
    {
        flagEmail=1;
    }

    if(phoneVal==false)
    {
        phone.setError("Please enter your phone correctly ");
        flagPhone=0;
    }
    else
    {
        flagPhone=1;
    }
    if(nameValue==null || nameValue.equals(" ") || nameValue.equals(""))
    {
        name.setError("Please enter your name");
        flagName=0;
    }
    else
    {
        flagName=1;
    }
    if(messageValue.isEmpty())
    {
        message.setError("Please enter the message");
        flagMsg=0;
    }
    else
    {
        flagMsg=1;
    }

    if (flagEmail==1 && flagPhone==1 && flagMsg==1 && flagName==1)
    {
        String s= String.valueOf(flagMsg+flagEmail+flagName+flagPhone);
        //Log.d("hello",s);

        FeedBackSend feedBackSend=new FeedBackSend();
        feedBackSend.execute();
    }

}
 
Example 13
Source File: EmailTypeRule.java    From data-binding-validator with Apache License 2.0 4 votes vote down vote up
@Override
protected boolean isValid(TextView view) {
    Pattern emailPattern = Patterns.EMAIL_ADDRESS;
    return emailPattern.matcher(view.getText()).matches();
}