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"/>
Related
How to read the device name from phone setting in android, As shown in below image how to read the first field that is "device name" in android.
In some phones, the device name is the same as the model name but in some phones both are different so how to particular read device name from phone settings in android?
Any help is appreciated!
here you go
Settings.Global.getString(getContentResolver(), Settings.Global.DEVICE_NAME)
You can directly use this, Use in your logcat to see the result.
Build.DEVICE
I'm building an Android embedded system which requires direct use of USB devices. The app will start when the device boot up. However, when accessing USB device normally, I have to request permission first. I don't want that permission popup comes up. I know there is a way to use intent-filter to directly get permission after user authorize it the first time but I don't know if this is the most ideal way. My device is a rooted android development board so basically I can change anything in the system. I know all the permission data is stored in /data/system/packages.xml but the USB permission is not real user-permission. I want to know if there is a place like /data/system/packages.xml that stores all the usb permissions like this:
For app: com.aaa.app, vendorId="1111" and productId="1111", permission="true".
I think there should be such a place to store this info cus the intent filter needs this. Anyone knows which file I should look at in the system? Thanks
After some investigation, finally found the place where this file is stored by myself. If you look at Android source code and locate com.android.server.usb.UsbSettingsManager (https://github.com/android/platform_frameworks_base/blob/4b1a8f46d6ec55796bf77fd8921a5a242a219278/services/usb/java/com/android/server/usb/UsbSettingsManager.java), all the USB related permission functions are here. And then you can search for mSettingsFile, you will find some code lines:
mSettingsFile = new AtomicFile(new File(
Environment.getUserSystemDirectory(user.getIdentifier()),
"usb_device_manager.xml"));
Then dig into the Environment class getUserSystemDirectory method, you will find the usb_device_manager.xml file is usually (system and ENV variable dependent if you look at the source code of Environment) located at
/data/system/users/0/usb_device_manager.xml
where 0 is the userId. This may very in your case. If I give the app the USB permit, then inside the file, it will show like this:
<?xml version='1.0' encoding='utf-8' standalone='yes' ?>
<settings>
<preference package="com.xxxx.testusb">
<usb-device vendor-id="1003" product-id="9220" class="0" subclass="0" protocol="0" manufacturer-name="Unknown" product-name="BlendMicro 8MHz" serial-number="" />
</preference>
</settings>
If you uninstall this app, then this entry will be removed automatically.
Here is a more detailed explanation I found just now. https://groups.google.com/forum/#!topic/android-platform/3duEI8rFERo
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"/>
I am developing an Android app (and soon iPhone app). I need a way to identify the handset from server side. I was thinking I could write a secret (a cryptographic string of some sort) in persistent storage on the device the first time the app is run, and use this to identify the handset next time it speaks to the back end server. Is this how to do it? Is there a better way?
Clarification: The question should have said, I want to identify the user of the app. I'm not interested in tracking the actual device.
As much I understood your question, you wish to identify from which device request is coming, not the build or firmware of the phone. In this case you could identify them from their IMEI number, with following code -
TelephonyManager telephonyManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
telephonyManager.getDeviceId();
Add the following permission into your Manifest file :
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
While looking for a way to give root permissions to an Android app, I read the official documentation and went through the permission FACTORY_TEST in the Manifest.Permissions page.
public static final String
FACTORY_TEST
Since: API Level 1
Run as a manufacturer test
application, running as the root user.
Only available when the device is
running in manufacturer test mode.
Constant Value:
"android.permission.FACTORY_TEST"
So I had my answer for the root question, but I was left with the FACTORY_TEST permission… Do you know when this permission should be used? I can't find a lot of documentation on the subject.
It's only for self educational purposes.
Thanks
Do you know when this permission should be used?
It should be used by a device manufacturer. AFAIK, it cannot be obtained by an ordinary SDK application.