Android Tablet Serial Number (not IMEI/DEVICE_ID/SERIAL) - android

i'm newbie
I'm using samsung tab P3100 (ICS 4.04).on menus setting->about device->status, i can got the serial number of device.How to get this serial number value programmatically ?
please help me...
android.os.Build.Serial <> Serial Number
Note :
Serial number <> IMEI <> android_id <> mac address

public class Utility {
Context context;
public AdParameters(Context context) {
this.context = context;
metrics = context.getResources().getDisplayMetrics();
}
public String getDeviceName() {
return android.os.Build.MODEL;
}
public String getIMEI() {
TelephonyManager telephonyManager = (TelephonyManager) context
.getSystemService(Context.TELEPHONY_SERVICE);
return telephonyManager.getDeviceId();
}
public String getMobielNo() {
TelephonyManager tm = (TelephonyManager) context
.getSystemService(context.TELEPHONY_SERVICE);
return tm.getLine1Number();
}
}
Android: How to programmatically access the device serial number shown in the AVD manager (API Version 8). Have a look at this link.

You can use the getprop command on the adb shell and check yourself that which of the files contains the correct Serial number.Many times the serial number is located on different files and code has to be device specific.
Foe samung Tab 3 you can use the following code:
try {
Class<?> c = Class.forName("android.os.SystemProperties");
Method get = c.getMethod("get", String.class, String.class);
serialnum = (String) (get.invoke(c, "sys.serialnumber", "unknown"));
} catch (Exception ignored) {
serialnum = "unknown";
}

Related

How do you get IMEI on a Verizon (CDMA vioice / LTE Data) device?

getDeviceId() returns the 14 digit MEID on Verizon phones (because it is a CDMA voice device). Is there a programmatic way to get the 15 digit IMEI (as it is listed in the Settings menu) instead?
Disclaimer: Solution uses non-published APIs. This does not represent best practice and can cause unintended results. API may not be implemented or may change. Use at your own risk.
There is a way to do this with reflection and a hidden Android API call. TelephonyManager has a public (but hidden) method getImei(). Not ideal, but the following works for my particular need.
private String getIMEI() throws NoIMEIException {
TelephonyManager mTelephonyMgr = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
try {
Method method = mTelephonyMgr.getClass().getMethod("getImei");
String imei = (String) method.invoke(mTelephonyMgr);
if (imei == null) {
throw new NoIMEIException();
} else {
return imei;
}
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
throw new NoIMEIException();
}
}

How to get real serial number of lenovo tab in android

I am trying to get the serial number of my Lenovo Idea Tab running Android. I tried all the options available in Google search, which are:
Class<?> c = Class.forName("android.os.SystemProperties");
Method get = c.getMethod("get", String.class);
String serial = (String) get.invoke(c, "ril.serialnumber" );
String serial_no = (String) get.invoke(c, "ro.serialno");
String serial_no1 = (String) get.invoke(c, "sys.serialnumber");
ro.serialno is giving a value as 8TYDE67HYLUOZPOZ, but the serial number shown in "Status -> About Tablet" is HGC2TKH4, and the printed serial number in the back side of the tab is also HGC2TKH4.
ril.serialnumber and sys.serialnumber are empty.
In some other tabs also, the ril.serialnumber is empty, but it is supposed to have the serial number, I hope.
Please, how can I find the real serial number of my device on Android?
I recently had to also get the SN for a lenovo tablet.
You can use the following methods
public static String getIMEI(Context context) {
TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
return telephonyManager != null ? (telephonyManager.getDeviceId() != null ? telephonyManager.getDeviceId() : "N/A") : "N/A";
}
public static String getSN() {
String deviceSN = "N/A";
try {
Class<?> propClass = Class.forName("android.os.SystemProperties");
Method getProp = propClass.getMethod("get", String.class, String.class);
deviceSN = (String) getProp.invoke(propClass, "gsm.sn1", "N/A");
} catch (Exception ignored) {
}
return deviceSN;
}
public static String getPN() {
String devicePN = "N/A";
try {
Class<?> propClass = Class.forName("android.os.SystemProperties");
Method getProp = propClass.getMethod("get", String.class, String.class);
devicePN = (String) getProp.invoke(propClass, "ro.lenovosn2", "N/A");
} catch (Exception ignored) {
}
return devicePN;
}
Lenovo has custom property names, you can use the following adb command to see all available props:
adb shell getprop
I used this code to get the serial number from the Lenovo tab 7 Essential (2017 model running Android 7.0). I was also using it to get Samsung serial numbers (Galaxy Camera 1/2 running Android 4 and a Tab A running 6, then updated to 7.1.1).
private static String UNKNOWN = "unknown";
static String GetDeviceSerialNumber() {
String serial;
if (Build.MANUFACTURER.toLowerCase().contains("lenovo")) {
serial = GetLenovoManufacturerSerialNumber();
} else {
serial = GetSamsungManufacturerSerialNumber();
}
if (serial == null || serial.equals(UNKNOWN)) {
serial = Build.SERIAL; // this is NOT usually the serial displayed on the device, but it returns something
}
return serial;
}
// http://stackoverflow.com/questions/14161282/serial-number-from-samsung-device-running-android
private static String GetSamsungManufacturerSerialNumber() {
String serial = GetSystemPropertyString("ril.serialnumber"); // older Samsung devices - works on Galaxy Camera 1
if (serial == null || serial.equals(UNKNOWN)) {
serial = GetSystemPropertyString("sys.serialnumber"); // newer Samsung devices
}
return serial;
}
// https://stackoverflow.com/questions/23773975/how-to-get-real-serial-number-of-lenovo-tab-in-android
private static String GetLenovoManufacturerSerialNumber() {
return GetSystemPropertyString("ro.lenovosn2");
}
private static String GetSystemPropertyString(String prop) {
try {
Class<?> c = Class.forName("android.os.SystemProperties");
Method get = c.getMethod("get", String.class, String.class);
return (String)get.invoke(c, prop, UNKNOWN);
} catch (Exception ignored) {
ignored.printStackTrace();
return null;
}
}
Hopefully that's helpful to someone.
HI you can get everything about your device hardware by using the following code.
Build.BRAND //Brand Name
Build.DEVICE //Device Name
Build.MODEL //Model No
Build.SERIAL //Serial No
import this namespace :: import android.os.Build;
Let me know if my answer is right or not.

Dual Sim Android

Is there a way that I can access the other sim in my android? I have an android Cherry Mobile Orbit which is a dual sim android phone. I want to develop an SMS application for my phone, but only the 1st sim will be access. I want to access the other sim, so that when i press enter to send the message, there will be a prompt, that which sim the message will be sent.
I know that it's propreitary, but the phone manufacturer has no feedback about it. Is there any other way? tweaking or something?
I think you can use dex2jar or apktool to reverse those app which runs on dual sim card devices, once you found the related "service manager", "telephony manager",some interface stub, or some key words like "Gemini" you can then use Java Reflection, reflects all of method of this class. Then you can achieve this goal.
This method can be used to select one SIM from 2 SIMs!
//above Android API 22
if (Build.VERSION.SDK_INT > 22) {
//for dual sim mobile
SubscriptionManager localSubscriptionManager = SubscriptionManager.from(this);
if (localSubscriptionManager.getActiveSubscriptionInfoCount() > 1) {
//if there are two sims in dual sim mobile
List localList = localSubscriptionManager.getActiveSubscriptionInfoList();
SubscriptionInfo simInfo = (SubscriptionInfo) localList.get(0);
SubscriptionInfo simInfo1 = (SubscriptionInfo) localList.get(1);
final String sim1 = simInfo.getDisplayName().toString();
final String sim2 = simInfo1.getDisplayName().toString();
}else{
//if there is 1 sim in dual sim mobile
TelephonyManager tManager = (TelephonyManager) getBaseContext()
.getSystemService(Context.TELEPHONY_SERVICE);
String sim1 = tManager.getNetworkOperatorName();
}
}else{
//below android API 22
TelephonyManager tManager = (TelephonyManager) getBaseContext()
.getSystemService(Context.TELEPHONY_SERVICE);
String sim1 = tManager.getNetworkOperatorName();
}
Then to send an SMS you can use the below method
public static boolean sendSMS(Context context, String smsText) {
SmsManager smsMan = SmsManager.getDefault();
SharedPreferences prefs = context.getSharedPreferences("uinfo", MODE_PRIVATE);
String sim = prefs.getString("sim", "No name defined");
String simName = prefs.getString("simName", "No name defined");
String toNum = "";
try {
if (Build.VERSION.SDK_INT > 22) {
SubscriptionManager localSubscriptionManager = SubscriptionManager.from(context);
if (localSubscriptionManager.getActiveSubscriptionInfoCount() > 1) {
int simID = Integer.parseInt(sim);
List localList = localSubscriptionManager.getActiveSubscriptionInfoList();
SubscriptionInfo simInfo = (SubscriptionInfo) localList.get(simID);
ArrayList<String> parts = smsMan.divideMessage(smsText);
SmsManager.getSmsManagerForSubscriptionId(simInfo.getSubscriptionId()).sendMultipartTextMessage(toNum, null, parts, null, null);
}else{
ArrayList<String> parts = smsMan.divideMessage(smsText);
smsMan.sendMultipartTextMessage(toNum, null, parts, null, null);
}
return true;
}else{
ArrayList<String> parts = smsMan.divideMessage(smsText);
smsMan.sendMultipartTextMessage(toNum, null, parts, null, null);
}
} catch (Exception e) {
}
return false;
}
Officially right now there is no API to support this, you have to contact the device manufacturer.
Assuming that you are developing the app for your own phone, and you are willing to go through the trouble of finding out the IDs (sim_id) assigned to each of your SIM cards (probably via checking the phone's log outputs, searching for sim_id, which was what I did), you can use the following code to set the default SIM for SMS sending:
int simId = <place desired SIM ID here>;
Intent simIntent = new Intent("android.intent.action.SMS_DEFAULT_SIM");
simIntent.putExtra("simid", simId);
sendBroadcast(simIntent);
Combined with some other UI prompt stuff (for actually 'picking' the preferred SIM), this should do the trick.
I'm not at all sure if this approach would work for you (although the code seems quite 'standard'); I figured it out with trial and error on my Mlais MX28 (with a customized ROM). But it's still worth a shot, I suppose. :)
UPDATE:
Strangely, the solution stopped working unexpectedly after a few updates to the app I was working on. But I came across another way (which seems to be more promising). (I believe this can be extended for other SIM selection scenarios as well, as the settings cache contains entries with names gprs_connection_sim_setting, voice_call_sim_setting, video_call_sim_setting and the like.)
ContentValues val = new ContentValues();
val.put("value", "here goes the preferred SIM ID");
getContentResolver().update(Uri.parse("content://settings/system"), val, "name='sms_sim_setting'", null);
(Unfortunately, this requires the android.permission.WRITE_SETTINGS permission.)

Issue - IMEI - HTC Flyer Tab [Telephony Manager]

I have HTC Flyer tab with version Android 2.3.4. I am not able to retrieve the IMEI number through TelephonyManager.getDeviceId(). It always return null.
Can somebody try to read out the IMEI on another device. I would like to know whether it is a Google or HTC problem.
This is a 'GSM' device. And it is brand new, didn't have any OS update.
FYI,
Included Manifest:
My programs on sumsung galaxy, Motorola xoom, and all smartphones working well.
Some of the tab devices do not have IMEI number. You can get WI-FI MAC address of the device.
WifiManager wifiMan = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
WifiInfo wifiInf = wifiMan.getConnectionInfo();
String ID = wifiInf.getMacAddress();
if you are getting null with TelephonyManager.getDeviceId(), use
Secure.getString(getApplicationContext().getContentResolver(), Secure.ANDROID_ID);
for example:
final TelephonyManager mTelephony = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
if (mTelephony.getDeviceId() != null){
AndroidDeviceId = mTelephony.getDeviceId();
}
else{
AndroidDeviceId = Secure.getString(getApplicationContext().getContentResolver(), Secure.ANDROID_ID);
}
even ANDROID_ID is not secure to use:
More specifically, Settings.Secure.ANDROID_ID. This is a 64-bit
quantity that is generated and stored when the device first boots. It
is reset when the device is wiped.
ANDROID_ID seems a good choice for a unique device identifier. There
are downsides: First, it is not 100% reliable on releases of Android
prior to 2.2 (“Froyo”). Also, there has been at least one
widely-observed bug in a popular handset from a major manufacturer,
where every instance has the same ANDROID_ID.
but i recommed use this method suggested in Android Developer´s Blog: Identifying App Installations:
public class Installation {
private static String sID = null;
private static final String INSTALLATION = "INSTALLATION";
public synchronized static String id(Context context) {
if (sID == null) {
File installation = new File(context.getFilesDir(), INSTALLATION);
try {
if (!installation.exists())
writeInstallationFile(installation);
sID = readInstallationFile(installation);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
return sID;
}
private static String readInstallationFile(File installation) throws IOException {
RandomAccessFile f = new RandomAccessFile(installation, "r");
byte[] bytes = new byte[(int) f.length()];
f.readFully(bytes);
f.close();
return new String(bytes);
}
private static void writeInstallationFile(File installation) throws IOException {
FileOutputStream out = new FileOutputStream(installation);
String id = UUID.randomUUID().toString();
out.write(id.getBytes());
out.close();
}
}
#SuppressWarnings("rawtypes")
Class SystemProperties = null;
SystemProperties = Class.forName("android.os.SystemProperties");
//Parameters Types
#SuppressWarnings("rawtypes")
Class[] paramTypes = new Class[1];
paramTypes[0] = String.class;
Method get=null;
get = SystemProperties.getMethod("get", paramTypes);
//Parameters
Object[] params = new Object[1];
params[0] = new String("ro.gsm.imei");
IMEI = (String) get.invoke(SystemProperties, params);

Will TelephonyManger.getDeviceId() return device id for Tablets like Galaxy Tab...?

I want to get the device id that will be unique for each Android device. I am presently developing for a Tablet device. Want to get unique device id and store the corresponding values...
So, i want to know whether Tablet devices will return a value if i use TelephonyManager.getDeviceId()...???Or is there any other value that is unique for each device???
TelephonyManger.getDeviceId() Returns the unique device ID, for example, the IMEI for GSM and the MEID or ESN for CDMA phones.
final TelephonyManager mTelephony = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
String myAndroidDeviceId = mTelephony.getDeviceId();
But i recommend to use:
Settings.Secure.ANDROID_ID that returns the Android ID as an unique 64-bit hex string.
String myAndroidDeviceId = Secure.getString(getApplicationContext().getContentResolver(), Secure.ANDROID_ID);
Sometimes TelephonyManger.getDeviceId() will return null, so to assure an unique id you will use this method:
public String getUniqueID(){
String myAndroidDeviceId = "";
TelephonyManager mTelephony = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
if (mTelephony.getDeviceId() != null){
myAndroidDeviceId = mTelephony.getDeviceId();
}else{
myAndroidDeviceId = Secure.getString(getApplicationContext().getContentResolver(), Secure.ANDROID_ID);
}
return myAndroidDeviceId;
}
This is not a duplicate question. As it turns out, Google's CTS require that getPhoneType of TelephonyManager needs to be none and getDeviceId of TelephonyManager needs to be null for non-phone devices.
So to get IMEI, please try to use:
String imei = SystemProperties.get("ro.gsm.imei")
Unfortunately, SystemProperties is a non-public class in the Android OS, which means it isn't publicly available to regular applications. Try looking at this post for help accessing it: Where is android.os.SystemProperties
Since Android 8 everything's changed. You should use Build.getSerial(), to get the serial number of the device and add the permission READ_PHONE_STATE.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
serial = Build.getSerial(); // Requires permission READ_PHONE_STATE
} else {
serial = Build.SERIAL; // Will return 'unknown' for device >= Build.VERSION_CODES.O
}
And get the IMEI or MEID this way:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
String imei = tm.getImei(); // Requires permission READ_PHONE_STATE
serial = imei == null ? tm.getMeid() : imei; // Requires permission READ_PHONE_STATE
} else {
serial = tm.getDeviceId(); // Requires permission READ_PHONE_STATE
}

Categories

Resources