Get Owner Name of an Android Device

This will help you get the owner name stored on the device:

Cursor c = getApplication().getContentResolver().query(ContactsContract.Profile.CONTENT_URI, null, null, null, null); 
c.moveToFirst();
textView.setText(c.getString(c.getColumnIndex("display_name")));
c.close();

Make sure you add this permission in the manifest:

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

You have java null pointer exception so name is null. Put your system.out.println() in the try and you won't have this error. After for getting the name I don't really know – Clad

Not my post but your answer : Get Android Device Name (for android device model my bad)

 android.os.Build.MODEL;

Here are two ways to do it :

How can I get the google username on Android?

How can I get the first name (or full name) of the user of the phone?


ContentResolver cr=getContentResolver();
Cursor curser = cr.query(ContactsContract.Profile.CONTENT_URI, null, null, null, null);
if(curser.getCount()>0){
    c.moveToFirst();
    String name=curser.getString(curser.getColumnIndex(
        ContactsContract.Profile.DISPLAY_NAME));
    Toast.makeText(MainActivity.this, "name"+name, Toast.LENGTH_SHORT).show();
}
c.close();

Tags:

Java

Android