2013-07-19 6 views
1
나는 현지 연락처 계정 type.Below를 얻기 위해 노력하고

삼성 기기에 잘하지만 소니 작동하지 작동 그것을위한 코드, micromax이 문제입니다 제안 etc.Please이지역 연락처 계정 유형을 얻는 방법은 무엇입니까?

public void GetDefaultAccountNameAndType() { 
String accountType = ""; 
String accountName = ""; 

long rawContactId = 0; 
Uri rawContactUri = null; 
ContentProviderResult[] results = null; 

ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>(); 

ops.add(ContentProviderOperation.newInsert(RawContacts.CONTENT_URI).withValue(RawContacts.ACCOUNT_NAME, null).withValue(RawContacts.ACCOUNT_TYPE, null).build()); 

try { 
    results = getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops); 
} catch(Exception e) { 
    e.printStackTrace(); 
} finally { 
    ops.clear(); 
} 

for (ContentProviderResult result : results) { 
    rawContactUri = result.uri; 
    rawContactId = ContentUris.parseId(rawContactUri); 
} 

Cursor c = getContentResolver().query(
     RawContacts.CONTENT_URI 
     , new String[] {RawContacts.ACCOUNT_TYPE, RawContacts.ACCOUNT_NAME} 
     , RawContacts._ID+"=?" 
     , new String[] {String.valueOf(rawContactId)} 
     , null); 

if(c.moveToFirst()) { 
    if(!c.isAfterLast()) { 
     accountType = c.getString(c.getColumnIndex(RawContacts.ACCOUNT_TYPE)); 
     accountName = c.getString(c.getColumnIndex(RawContacts.ACCOUNT_NAME)); 
    } 
} 

getContentResolver().delete(rawContactUri, null, null); 

c.close(); 
c = null; 

System.out.println(accountType); 
System.out.println(accountName); 

//preference.setString("contactAccountType", accountType); 
//preference.setString("contactAccountName", accountName); 

를 해결하기 위해 }

답변

0

TRY 이것은 소니에서는 작동하지만 삼성에서는 작동하지 않습니다. 왜 그런지 모르겠다. 나는 또한 같은 문제를 조사하고있다.

/** 
* Get All Account available in Phone and add into list 
*/ 
private void getAllAccounts() { 
    int counter = 0; 
    final AccountManager accManager = AccountManager 
      .get(Activity.this); 
    final Account accounts[] = accManager.getAccounts(); 

    for (int i = 0; i < accounts.length; i++) { 
     Log.i(TAG, "Name " + accounts[i].name + ", Type " 
        + accounts[i].type); 
    } 
} 
관련 문제