1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-08-13 17:03:48 -04:00

Issue 737

Don't crash if unable to find the owner name.  The actual owner name
fetching code will need to be updated for Android 2.0, but this will
help for now.
This commit is contained in:
Daniel Applebaum 2009-11-07 15:32:05 +00:00
parent 044770f85b
commit 2f4b9a1178

View File

@ -137,24 +137,48 @@ public class AccountSetupBasics extends K9Activity
private String getOwnerName() {
String name = null;
String projection[] = {
ContactMethods.NAME
};
Cursor c = getContentResolver().query(
Uri.withAppendedPath(Contacts.People.CONTENT_URI, "owner"), projection, null, null,
null);
if (c.getCount() > 0) {
c.moveToFirst();
name = c.getString(0);
c.close();
}
if (name == null || name.length() == 0) {
Account account = Preferences.getPreferences(this).getDefaultAccount();
if (account != null) {
name = account.getName();
try
{
String projection[] = {
ContactMethods.NAME
};
Cursor c = getContentResolver().query(
// TODO: For Android 2.0, needs to change to ContactsContract.People...
Uri.withAppendedPath(Contacts.People.CONTENT_URI, "owner"), projection, null, null,
null);
if (c.getCount() > 0) {
c.moveToFirst();
name = c.getString(0);
c.close();
}
}
catch (Exception e)
{
Log.e(Email.LOG_TAG, "Could not get owner name, using default account name", e);
}
if (name == null || name.length() == 0) {
try
{
name = getDefaultAccountName();
}
catch (Exception e)
{
Log.e(Email.LOG_TAG, "Could not get default account name", e);
}
}
if (name == null) {
name = "";
}
return name;
}
private String getDefaultAccountName()
{
String name = null;
Account account = Preferences.getPreferences(this).getDefaultAccount();
if (account != null) {
name = account.getName();
}
return name;
}