This question already has answers here:
Get Android Phone Model programmatically , How to get Device name and model programmatically in android?
(16 answers)
Closed 6 years ago.
How to get the device model name ? I have a Yuphoria 5010 which displays YU5010 in device Model Number, I want to fetch the full name of the device? I want the fetch the exact string given below:
Yuphoria 5010 6.0 Marshmallow
It was really simple, just call:
String model = Build.MODEL;
Update: This code will print the exact string you requested:
String reqString = Build.MANUFACTURER
+ " " + Build.MODEL + " " + Build.VERSION.RELEASE
+ " " + Build.VERSION_CODES.class.getFields()[android.os.Build.VERSION.SDK_INT].getName();
Prints:
Samsung Note 4 6.0 MARSHMALLOW
LGE LG-D410 4.4.2 KITKAT
On many popular devices the market name of the device is not available. For example, on the Samsung Galaxy S6 the value of Build.MODEL could be "SM-G920F", "SM-G920I", or "SM-G920W8".
So for getting full device name you can use a library which is available on github . Link of AndroidDeviceLibrary is here https://github.com/shubhamsharmacs/AndroidDeviceNames
Now how to use these library :-
put these in your build.gradle file
compile 'com.jaredrummler:android-device-names:1.0.9'
Now these operations are :
Get the name of the current device:
String deviceName = DeviceName.getDeviceName();
The above code will get the correct device name for the top 600 Android devices. If the device is unrecognized, then Build.MODEL is returned. This can be executed from the UI thread.
Get the name of a device using the device's codename:
// Retruns "Moto X Style"
DeviceName.getDeviceName("clark", "Unknown device");
Get information about the device:
DeviceName.with(context).request(new DeviceName.Callback() {
#Override public void onFinished(DeviceName.DeviceInfo info, Exception error) {
String manufacturer = info.manufacturer; // "Samsung"
String name = info.marketName; // "Galaxy S7 Edge"
String model = info.model; // "SAMSUNG-SM-G935A"
String codename = info.codename; // "hero2lte"
String deviceName = info.getName(); // "Galaxy S7 Edge"
// FYI: We are on the UI thread.
}
});
The above code loads JSON from a generated list of device names based on Google's maintained list. It will be up-to-date with Google's supported device list so that you will get the correct name for new or unknown devices. This supports over 10,000 devices.
This will only make a network call once. The value is saved to SharedPreferences for future calls.
You can get the device details by using the below code.
String s="Debug-infos:\n";
s += "OS Version: " + System.getProperty("os.version") + "(" + android.os.Build.VERSION.INCREMENTAL + ")\n";
s += "OS API Level: " + android.os.Build.VERSION.RELEASE + "(" + android.os.Build.VERSION.SDK_INT + ")\n";
s += "Device: " + android.os.Build.DEVICE + "\n";
s += "Model (and Product): " + android.os.Build.MODEL + " ("+ android.os.Build.PRODUCT + ")\n";
USe this code for get device Model
import android.os.Build;
String deviceModel = Build.MODEL;
if you want get this info in android 6.0 Marshmellow so before this get info give the run time permission
Manifest.permission.READ_PHONE_STATE
Related
Here is the setup:
A coworker created a small firmware that changes the value of a custom characteristic within a custom service (non standard unique 128 bit UUID) about once every second. The device used to transmit uses a BLE (Bluetooth low power) implementation.
I needed to implement a small App (as a working example ONLY) to monitor said value. However I've run into a small problem. I've follwed the instructions here: http://doc.qt.io/qt-5/qtbluetooth-le-overview.html and I've manged to discover the service and "read it" (I get us UUID) by using this code:
void BLETest::on_stateChanged(QLowEnergyService::ServiceState state){
#ifdef DBUG
logger->out("Service Monitor State: " + lowEnergyServiceStateToString(state),Logger::LC_ORANGE);
#endif
if (state == QLowEnergyService::ServiceDiscovered){
QString chars = "";
QList<QLowEnergyCharacteristic> clist = monitoredService->characteristics();
for (int i = 0; i < clist.size(); i++){
chars = clist.at(i).uuid().toString() + " - " + clist.at(i).name() + ": " + QString(clist.at(i).value());
chars = chars + ". Value size: " + QString::number(clist.at(i).value().size()) + "<br>";
}
if (chars.isEmpty()){
chars = "No characteristics found";
}
logger->out(chars);
}
}
Now this prints the UUID of the service but the size of the value byte array is zero. Using another (private App) we can actually see the value field for the characteristic in that service changing. Furthermore, even though there was a connection done to the service's object characteristicChanged singal, that signal is never triggered, which I imagine is because the characteristic value can't be read.
My question is: Is there anything wrong with the code that you can't think of? Or is it simply that is not possible to monitor custom services and characteristics with the current BLE implementation of Qt Bluetooth?
PD: I'm using Qt 5.7.1
you must enable the chracteristic notification by write 0x01 to client characteristic configuration descriptor (CCCD).
foreach(QLowEnergyCharacteristic c, srv->characteristics()){
QLowEnergyDescriptor d = c.descriptor(QBluetoothUuid::ClientCharacteristicConfiguration);
if(!c.isValid()){
continue;
}
if(c.properties() & QLowEnergyCharacteristic::Notify){ // enable notification
srv->writeDescriptor(d, QByteArray::fromHex("0100"));
}
if(c.properties() & QLowEnergyCharacteristic::Indicate){ // enable indication
srv->writeDescriptor(d, QByteArray::fromHex("0200"));
}
}
The following screenshot of a generic tablet shows an example of Firmware version:
We have tried pretty much everything of Android Build, none of them is the firmware version.
Firmware is the operating software available on an Android device, and it is available in different versions designed by different manufacturers. Basically it's the device-specific part of the software. For example, you may have Android 4.2.2 running on your phone, but have a firmware number that looks completely different because it relates to more details than just Operating System. The firmware number consists of several elements, all of which are essential for the functioning of the phone:
PDA: Android operating system and your customizations.
Phone: the actual identifier of your device.
CSC (Country Exit Code): the languages and country-specific parameters.
Bootloader: the boot loader program that runs at startup to all unit processes.
Software Build Version is basically the Firmware Version.
See android.os.Build.VERSION. SDK or SDK in contain the API version. android.os.Build.VERSION_CODES contains the relevant constants.
String deviceSoftwareVersion=telephonyManager.getDeviceSoftwareVersion();
Refer to this Build.VERSION
Procedure to use it in code.
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.GINGERBREAD) {
// only for gingerbread and newer versions
}
This can be also checked by through code
System.out.println("button press on device name = "+android.os.Build.MODEL +" brand = "+android.os.Build.BRAND +" OS version = "+android.os.Build.VERSION.RELEASE + " SDK version = " +android.os.Build.VERSION.SDK_INT);
UPDATE
Try this one -
android.os.Build.FINGERPRINT
android.os.Build.BOARD
Build.HOST
Build.ID
Build.SERIAL
Check the following Code.
FINAL UPDATE
String mString = "";
mString.concat("VERSION.RELEASE {" + Build.VERSION.RELEASE + "}");
mString.concat("\nVERSION.INCREMENTAL {" + Build.VERSION.INCREMENTAL + "}");
mString.concat("\nVERSION.SDK {" + Build.VERSION.SDK + "}");
mString.concat("\nBOARD {" + Build.BOARD + "}");
mString.concat("\nBRAND {" + Build.BRAND + "}");
mString.concat("\nDEVICE {" + Build.DEVICE + "}");
mString.concat("\nFINGERPRINT {" + Build.FINGERPRINT + "}");
mString.concat("\nHOST {" + Build.HOST + "}");
mString.concat("\nID {" + Build.ID + "}");
((TextView) findViewById(R.id.textView1)).setText(mString);
You can also useBuild.DISPLAY
A build ID string meant for displaying to the user
I used following code to get firmware version of my device:
public String getFirmwareVersion() {
try {
Class cls = Class.forName("android.os.SystemProperties");
Method method = cls.getMethod("get", String.class);
method.setAccessible(true);
return (String) method.invoke(cls, FIRMWARE_VERSION_PROPERTY);
} catch (Exception e) {
return null;
}
}
As FIRMWARE_VERSION_PROPERTY I used "ro.product.version"
I've got this property address from the device manufacturer.
This address can vary for different devices and manufacturers, so it's advisable to contact manufacturer's tech support to get the correct one.
I'm testing Nearby connection API with the sample application available here: https://github.com/googlesamples/android-nearby
It seems that this is not working for some devices. I successfully connected Samsung Galaxy S3 with Nexus 7, in both directions (S3 as host, N7 as slave and vice versa). However, when I try to connect Samusung Galaxy S3 to Nexus 5, the connection ALWAYS fails, with status code 8005.
Below you can see the method invoked by slave (discovering device) in order to connect to host (advertising device).
private void connectTo(String endpointId, final String endpointName) {
debugLog("connectTo:" + endpointId + ":" + endpointName);
// Send a connection request to a remote endpoint. By passing 'null' for the name,
// the Nearby Connections API will construct a default name based on device model
// such as 'LGE Nexus 5'.
String myName = null;
byte[] myPayload = null;
Nearby.Connections.sendConnectionRequest(mGoogleApiClient, myName, endpointId, myPayload,
new Connections.ConnectionResponseCallback() {
#Override
public void onConnectionResponse(String endpointId, Status status,
byte[] bytes) {
Log.d(TAG, "onConnectionResponse:" + endpointId + ":" + status);
if (status.isSuccess()) {
debugLog("onConnectionResponse: " + endpointName + " SUCCESS");
Toast.makeText(MainActivity.this, "Connected to " + endpointName,
Toast.LENGTH_SHORT).show();
mOtherEndpointId = endpointId;
updateViewVisibility(STATE_CONNECTED);
} else {
debugLog("onConnectionResponse: " + endpointName + " FAILURE. ResponseCode=" + status.getStatusCode() + " statusMessage=" + status.getStatusMessage() );
}
}
}, this);
}
The result I always get is :
11-17 18:48:50.678 11133-11133/com.google.example.connectionsquickstart D/MainActivity: onConnectionResponse: Samsung GT-I9300 FAILURE. ResponseCode=8005 statusMessage=null
Any clue what is going on?
The error you're getting is STATUS_NOT_CONNECTED_TO_ENDPOINT (from Reference docs). Both devices need to be connected to the same WiFi which has internet access.
I assume you're talking about the connections-quickstart sample. See this github issue here https://github.com/googlesamples/android-nearby/issues/6
. The API used on this sample relies on multicast apparently, which will be dependent certainly on your router and apparently also on your devices:
And apparently you have that on Nexus 7 but not Nexus 5:
https://code.google.com/p/android/issues/detail?id=51195
chuckd73...#gmail.com
This is a show stopper for us on the Nexus 4. Our app relies on multicast and cannot be implemented any other way. It's interesting that the Nexus 7 actually does have this implemented, but not the 4.
Jan 8, 2014 #3 jan.zibu...#gmail.com
The problem persists on the Nexus 5.
So I bet that on your current wifi you'be able to connect your nexus 7 to anything.
Just to be clear, you can have problems trying to RECEIVE multicast packets: Android can not receive multicast packet
I need to get number of Sim one while having dual sim android phone and not getting this by following code.
I am getting everything exact the same as it is but not getting the sim number
In My manifest file
uses-permission android:name="android.permission.READ_PHONE_STATE"
My main activity
TelephonyManager tel = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
TextView txt=(TextView)findViewById(R.id.textView1);
txt.setText("Operator Code : " + tel.getSimOperator().toString()
+ "\nOperator Name : " + tel.getSimOperatorName().toString()
+ "\nCountry ISO : " + tel.getSimCountryIso().toString()+"sim"+tel.getLine1Number()+" Serial Number : " + tel.getSimSerialNumber().toString()
+ "\nMobile Number : " + tel.getLine1Number().toString());
Please help with the example code
I just figured it out today....... and that's help me in clearing many things
What does getLine1Number() return with dual SIM phones?
I am using the following snippet to log all available (and unavailable) voices currently on phone:
ArrayList<String> availableVoices = intent.getStringArrayListExtra(TextToSpeech.Engine.EXTRA_AVAILABLE_VOICES);
String availStr = "";
for (String lang : availableVoices)
availStr += (lang + ", ");
Log.i(String.valueOf(availableVoices.size()) + " available langs: ", availStr);
ArrayList<String> unavailableVoices = intent.getStringArrayListExtra(TextToSpeech.Engine.EXTRA_UNAVAILABLE_VOICES);
String unavailStr = "";
for (String lang : unavailableVoices)
unavailStr += (lang + ", ");
Log.w(String.valueOf(unavailableVoices.size()) + " unavailable langs: ", unavailStr);
The logged result is somehwat bewildering, since I know beyond certainty that I have multiple languages installed and I can even hear the TTS speaking in eng-USA, yet the log shows:
1 available langs: eng-GBR,
30 unavailable langs: ara-XXX, ces-CZE, dan-DNK, deu-DEU, ell-GRC,
eng-AUS, eng-GBR, eng-USA, spa-ESP, spa-MEX, fin-FIN, fra-CAN,
fra-FRA, hun-HUN, ita-ITA, jpn-JPN, kor-KOR, nld-NLD, nor-NOR,
pol-POL, por-BRA, por-PRT, rus-RUS, slk-SVK, swe-SWE, tur-TUR,
zho-HKG, zho-CHN, zho-TWN, tha-THA,
Why is this inconsistent behavior? (note that eng-GBR appears in both the available and unavailable lists...)
It turns out that as far as text-to-speech in Android 2.x goes, it's the wild west out there: Every and any installed 3rd-party TTS engine can modify the output of this EXTRA_AVAILABLE_VOICES function however they desire, regardless whether checked/unchecked or selected/unselected as default.
I just tried uninstalling all TTS engines from my phone, leaving only the hard-coded Pico, and the result match exactly what I expected:
6 available voices: deu-DEU, eng-GBR, eng-USA, spa-ESP, fra-FRA,
ita-ITA,
0 unavailable voices:
I don't mind the output of this function dynamically refer to the currently selected (i.e. default) TTS engine, but the fact is that once a 3rd party TTS engine is installed, this function's output doesn't make any sense, because it ignores any settings.
Also note that the name misleading: It's available languages, not voices!
I am posting this answer with the hope that it will help someone save the time & agony of discovering this the hard way.