requestPermission();
}
public static final int GRT_ACCOUNT_REQ_CODE = 123;
public void requestPermission() {
if (ContextCompat.checkSelfPermission(getActivity(), Manifest.permission.GET_ACCOUNTS) != PackageManager.PERMISSION_GRANTED) {
if (ActivityCompat.shouldShowRequestPermissionRationale(getActivity(), Manifest.permission.GET_ACCOUNTS)) {
requestPermissions(new String[]{Manifest.permission.GET_ACCOUNTS}, GRT_ACCOUNT_REQ_CODE);
Toast.makeText(getActivity(), R.string.applock_auto_email, Toast.LENGTH_SHORT).show();
} else {
requestPermissions(new String[]{Manifest.permission.GET_ACCOUNTS}, GRT_ACCOUNT_REQ_CODE);
}
}else{
setAutoEmail();
}
}
public void setAutoEmail(){
try {
AccountManager accountManager = AccountManager.get(getActivity());
Account[] accounts = accountManager.getAccounts();
for (int i = 0; i if (Patterns.EMAIL_ADDRESS.matcher(accounts[i].name).matches()) {
mEtConfirmEmailAddress.setText(accounts[i].name);
mEtEmailAddress.setText(accounts[i].name);
return;
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
public static final Pattern EMAIL_ADDRESS
= Pattern.compile(
"[a-zA-Z0-9\+\.\_\%\-\+]{1,256}" +
"\@" +
"[a-zA-Z0-9][a-zA-Z0-9\-]{0,64}" +
"(" +
"\." +
"[a-zA-Z0-9][a-zA-Z0-9\-]{0,25}" +
")+"
);
服务器托管,北京服务器托管,服务器租用 http://www.fwqtg.net
机房租用,北京机房租用,IDC机房托管, http://www.e1idc.net