android - Retrieve device Gmail accounts -
i trying accounts info configured in gmail application, like, username, email address, etc.
i using below code -
public arraylist<string> get_email_addresses() { arraylist<string> names = new arraylist<>(); account[] accounts = accountmanager.get(feedbackfragment.this.getactivity()).getaccounts(); if (accounts == null) { toast.maketext(feedbackfragment.this.getactivity(), "cannot access email accounts database", toast.length_short).show(); return null; } if (accounts.length <= 0) { toast.maketext(feedbackfragment.this.getactivity(), "no accounts found", toast.length_short).show(); return null; } (account account : accounts){ names.add(account.name); toast.maketext(feedbackfragment.this.getactivity(),account.name, toast.length_short).show(); } return names; }
but no retrieves info have configured multiple accounts , returns message "no accounts found"
.
is wrong in code? have idea how rectify this?
thank you!
Comments
Post a Comment