How to get user name on Android similar to iOS? - android

In Android you can set a username for the device. I've set up a few devices where it asked me for my first name and last name. I was wondering how to retrieve this. In iOS you can get a name like "Kate's iPhone" for the device name which is what I want to do on Android. Additionally in a game I'd like to fill in the Characters name with the persons name. So I could essentially say String.format("Hello, %s", getUsername); Is this possible in Android down to API 10? The only thing I've found is UserManager with a getUserName() method, but it is only available at API level 17 which I think lines up with when Android allowed tablets to have multi user support... so I'm not sure it will actually give a valid response on a phone. Does anyone have any ideas?
I am not looking for device name (e.g. Nexus 7, Nexus 4, Samsung Galaxy S5).

This works on a real phone, in an Emulator you will get an empty String.
BluetoothAdapter myDevice = BluetoothAdapter.getDefaultAdapter();
String deviceName = myDevice.getName();
Toast.makeText(this, "Phone "+deviceName, Toast.LENGTH_LONG).show();
Remember to add the permission to the Manifest:
<uses-permission android:name="android.permission.BLUETOOTH"/>

Related

How to get Android Device Serial Number (on Android 10 API level 28) in UNITY Oculus Quest 2 and Vive Focus

I need serial number or something that works similarly because our company creates applications for VR and I create web API that must recognize a specific device in several applications, because we assign subscriptions to the customer per device.
SystemInfo.deviceUniqueIdentifier can't be because it generates a different id for each application.
So far I have used this:
AndroidJavaObject jo = new AndroidJavaObject("android.os.Build");
string serial = jo.GetStatic<string>("SERIAL");
return serial;
but on android 10 it stops working and for HTC VIVE Focus HMD this function does not work at all.
Perfectly, I would use some id that is invariant for a given device if it's possible. I also allow the use of some id that will be created for the user and removed when the device is reset to initial state.

How to fetch Device Name (NOT Build.MODEL) from Android programatically?

I have been searching for code through which I can fetch Device's name defined by user for his own device .
Have gone through various stackoverflow questions , but none seems to work for me ?
Image as seen in below : Will require Thanks Thanks (SM-T211 ) from android code
Try this:
String ownerInfo = Settings.Secure.getString(getContentResolver(),
"lock_screen_owner_info");
As of Android 4.4.2 the owner info value is moved to lock screen database,/data/system/locksettings.db to which 3rd-party apps have no read/write access. That's, there is no reliable way of reading owner info for later Android versions except for rooted device.
You need to get build.prop file of system which is possible either if your device is rooted or if your has system privileges....
heres the code you may follow to get and edit build.prop
Check this App in Play Store. build.prop Editor. Since it's open source, and the code is extremely simple, you can use it as a stating point: https://github.com/nathanpc/Build.prop-Editor
Try this :
BluetoothAdapter myDevice = BluetoothAdapter.getDefaultAdapter();
String deviceName = myDevice.getName();
Make sure you add to your manifest:
<uses-permission android:name="android.permission.BLUETOOTH"/>

Android Mobile Identification Number (MIN)

My android application needs to retrieve the phone number of the device. I'm using the method getLine1Number() to retrieve it, however on some phones it returns a wrong value.
Code:
TelephonyManager tMgr = (TelephonyManager)c.getSystemService(Context.TELEPHONY_SERVICE);
String number = tMgr.getLine1Number();
The phone returning a wrong value is a Samsung Galaxy S6 running android 6.0.1. In the phone settings under Phone number it displays the same wrong value, however under MIN the correct phone number is displayed.
Can anyone give me any ideas or solutions to this problem? I haven't been able to find any way of retrieving the MIN value from an android phone. Nor have I identified why this phone returns a wrong value.
There is no function to get the phone number of a device. Because of the ways some carriers set up SIMs, its actually possible that the device itself doesn't know what its own phone number is. If you actually need a phone number, you need to ask the user for it. If you need a unique id for the phone, other things like ANDROID_ID are more appropriate (remember not ever android device even has a phone number- tablets, watched, and TVs may not).

The phone return empty when I want to get the phone number

Some phones return null when I want to get the phone number. In other phones I get the phone number.
This happens when Settings -> About Phone -> Status -> My phone number is "Unkow". Not writed there the phone number.
Why is this happening?How can I get a phone number ?
The code:
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
And:
TelephonyManager tMgr = (TelephonyManager)getApplicationContext().getSystemService(Context.TELEPHONY_SERVICE);
String mPhoneNumber = tMgr.getLine1Number();
Your code is perfect to get phone number of Android device.It will return you number.But sometimes it gives you null because that devices Service provider has not given permission to do that.
Means It works like : Android devices Request SIM card/Service provider for card info with phone number. And In response, Some provider have returned phone number of user and some has refused to do so.
Can you clarify what specifically you're asking for? If you're saying that it happens when in your phone's settings, under About Phone->Status->My phone number, it says "Unknown", then unfortunately that's not a programming question and not a question for here. Is that the case?
You cannot get device phone number in any ways. It depends on the service provider, some may allow access and some may not since it is completely dependent on the network access privileges. But in rare case you would get the phone number once the user has configured their own mobile number with the SIM card provider. The other way to do this by fetching the number from Facebook that too the user should have registered their mobile number, whereas the earlier versions of whatsapp provides this feature, but it is not compatible with the newer ones.
Note: It works with few custom phones which provides the access.(i.e., phones synced with only particular network providers)

How to get Samsung Android Device Name programmatically?

Other similar questions in SO are answered by retrieving the Build.MODEL name.
But what I would really like is to get the customizable Device name on Samsung Devices. I know it is customizable because on my Galaxy Note, I can change it from the settings->About device. For example, below, I would like to retrieve the "Milky Way" string.
There is no common way getting this, since it's not a "android-feature" more likely a Samsung Feature afaik.
Try getting it with this, which worked on my galaxy s3, s4 and s5
BluetoothAdapter myDevice = BluetoothAdapter.getDefaultAdapter();
String deviceName = myDevice.getName();
Do not forget to add the bluetooth permissions.
<uses-permission android:name="android.permission.BLUETOOTH"/>
I tried
BluetoothAdapter myDevice = BluetoothAdapter.getDefaultAdapter();
String deviceName = myDevice.getName();
still returns the SM-G900H.
After some research I found the device_name in /data/data/com.android.providers.settings/da‌​tabases/settings‌​.db
I manage to get it using following shell command
settings get system device_name
Code:
String deviceName = Settings.System.getString(getContentResolver(), "device_name");
Settings.Global.getString(context.getContentResolver(), "device_name")
It working for me.

Categories

Resources