2015-08-24 55 views
1

我正在嘗試在android中使用電話號碼執行註冊活動,正如whatsapp和許多其他應用程序所做的那樣。但我也需要知道用戶的名字,但不提示用戶自己輸入。可能嗎? whatsApp如何設法做到這一點? 在這裏尋找任何可能的建議。謝謝。WhatsApp如何在註冊期間找到用戶的名字?

+0

請看看這兩個帖子:[這](http://stackoverflow.com/questions/2727029 /我怎麼能得到谷歌用戶名在Android上)和[這一個](http://stackoverflow.com/questions/2727029/how-can-i-get-the -google-username-on-android) – NightFury

回答

1

您可以使用ContactsContract.Profile

String name = ""; 
    Cursor c = getApplication().getContentResolver().query(ContactsContract.Profile.CONTENT_URI, null, null, null, null); 
    if(c.moveToFirst()) { 
    name = c.getString(c.getColumnIndex("display_name")); 
    c.close(); 
    } 

您需要的權限過於

<uses-permission android:name="android.permission.READ_PROFILE"/> 
<uses-permission android:name="android.permission.READ_CONTACTS"/> 

閱讀本Get Owner Name of an Android Device

+0

我可以獲取有關業主的其他信息? –

+0

閱讀更多信息http://developer.android.com/reference/android/provider/ContactsContract.Profile.html – Emil

相關問題