Im trying to do something like this
i have found this pop up dialog in a few apps like shopify app and discord app , once you open sign up or login page dialog pop up with all possible emails.
Now my question how to achieve something like this without asking the user for contact permission.
My current Code is :
private void addAdapterToViews() {
Account[] accounts = AccountManager.get(getActivity()).getAccounts();
Set<String> emailSet = new HashSet<String>();
for (Account account : accounts) {
if (EMAIL_PATTERN.matcher(account.name).matches()) {
emailSet.add(account.name);
}
}
binding.autoemail.setAdapter(new ArrayAdapter<String>(getActivity(), android.R.layout.simple_dropdown_item_1line, new ArrayList<String>(emailSet)));
}
private boolean mayRequestContacts() {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
return true;
}
if (getActivity().checkSelfPermission(READ_CONTACTS) == PackageManager.PERMISSION_GRANTED) {
return true;
}
if (shouldShowRequestPermissionRationale(READ_CONTACTS)) {
requestPermissions(new String[]{READ_CONTACTS}, REQUEST_READ_CONTACTS);
Snackbar.make(binding.autoemail, R.string.permission_rationale, Snackbar.LENGTH_INDEFINITE)
.setAction(android.R.string.ok, new View.OnClickListener() {
@Override
@TargetApi(Build.VERSION_CODES.M)
public void onClick(View v) {
requestPermissions(new String[]{READ_CONTACTS}, REQUEST_READ_CONTACTS);
}
});
} else {
requestPermissions(new String[]{READ_CONTACTS}, REQUEST_READ_CONTACTS);
}
return false;
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
@NonNull int[] grantResults) {
if (requestCode == REQUEST_READ_CONTACTS) {
if (grantResults.length == 1 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
addAdapterToViews();
}
}
}
This code is working fine for me once the user try to type any letters in email edittext
if permission is granted.
4
Answers
So far what i have found out is using google service to get all of the user emails without any permission with the following code :
Inside
OnCreate()
or Button click :And to get results
But my problem is that the user email dialog open in pre made sign in activty, but i would like to use my own. Any tips ? here is the source google library
its not possible to get access user confidential information (like email id ) without runtime Permissions.
Maybe this is not what you are looking for, but I really recommend that you take a look to Authentication with Firebase and the helper library FirebaseUI. They have all that boilerplate already implemented and it is really easy to config, customize and setup.
Credentials API to retrieve sign-in hints, such as the user’s name and email address.
On Android 6.0 (Marshmallow) and newer, your app does not need to request any device or runtime permissions to retrieve sign-in hints with the Credentials API
HintRequest Builder Google Documentation