2011-11-16 82 views

回答

0

試試這個:

private String getUserProfileName() 
{ 
    ContentResolver cr = getContentResolver(); 
    Cursor cur = cr.query(Profile.CONTENT_URI, null, null, null, null); 
    while (cur.moveToNext()) 
    { 
     int isUser = cur.getInt(cur.getColumnIndex(Profile.IS_USER_PROFILE)); 
     if (isUser > 0) 
     { 
      isNewContact = false; 
      String name = cur.getString(cur.getColumnIndex(Profile.DISPLAY_NAME));      
      Log.e(TAG, "user profile name " + name); 
      cur.close(); 
      return name; 
     } 
    } 

    Log.e(TAG, "no user profile found!"); 
    cur.close(); 
    isNewContact = true; 
    return null; 
} 

確保允許添加到您的AndroidManifest文件:android.permission.READ_PROFILE

相關問題