Exception thrown for missing manufacturer when retrieving getDeviceName()
Hello, I am using the library to retrieve the device market name, which works, but i always see this exception below for the missing manufacturer?
org.json.JSONException: No value for manufacturer
at org.json.JSONObject.get(JSONObject.java:389)
at org.json.JSONObject.getString(JSONObject.java:550)
at com.jaredrummler.android.device.DeviceName$DeviceInfo.
It is a very simple code:
I have initialized the lib:
DeviceName.init(this)
Then call:
private fun setupDeviceInformation() {
try {
g3ptDeviceModelInformation =
"${Build.MODEL} (${Build.MANUFACTURER}) (${DeviceName.getDeviceName()})"
G3PTenLog.d(TAG, "[SVC] DeviceName: $g3ptDeviceModelInformation")
} catch (e: Exception) {
G3PTenLog.e(TAG, "[SVC] Error retrieving device name: $e")
e.printStackTrace()
}
}
I have the same trouble. After I called:
/**
* Will return a model of device(For example: Nexus 5)
* @return String
*/
public static String getDeviceModel() {
if (Build.MODEL.equals(DeviceName.getDeviceName())) {
return Build.MODEL;
}
return DeviceName.getDeviceName() + " (" + Build.MODEL + ")";
}
Got error:
org.json.JSONException: No value for manufacturer
at org.json.JSONObject.get(JSONObject.java:400)
at org.json.JSONObject.getString(JSONObject.java:561)
at com.jaredrummler.android.device.DeviceName$DeviceInfo.<init>(DeviceName.java:374)
at com.jaredrummler.android.device.DeviceName$DeviceInfo.<init>(DeviceName.java:347)
at com.jaredrummler.android.device.DeviceName.getDeviceInfo(DeviceName.java:186)
at com.jaredrummler.android.device.DeviceName.getDeviceName(DeviceName.java:138)
at com.jaredrummler.android.device.DeviceName.getDeviceName(DeviceName.java:111)
Device: Xiaomi Redmi Note 8 Pro
W/System.err: org.json.JSONException: No value for manufacturer W/System.err: at org.json.JSONObject.get(JSONObject.java:399) W/System.err: at org.json.JSONObject.getString(JSONObject.java:560) W/System.err: at com.jaredrummler.android.device.DeviceName$DeviceInfo.<init>(DeviceName.java:374) W/System.err: at com.jaredrummler.android.device.DeviceName$DeviceInfo.<init>(DeviceName.java:347) W/System.err: at com.jaredrummler.android.device.DeviceName.getDeviceInfo(DeviceName.java:186) W/System.err: at com.jaredrummler.android.device.DeviceName.getDeviceName(DeviceName.java:138) W/System.err: at com.jaredrummler.android.device.DeviceName.getDeviceName(DeviceName.java:111) W/System.err: ... W/System.err: at android.net.ConnectivityManager$NetworkCallback.onAvailable(ConnectivityManager.java:3 W/System.err: at android.net.ConnectivityManager$CallbackHandler.handleMessage(ConnectivityManager.java W/System.err: at android.os.Handler.dispatchMessage(Handler.java:107) W/System.err: at android.os.Looper.loop(Looper.java:224) W/System.err: at android.os.HandlerThread.run(HandlerThread.java:67)
Same for me Samsung galaxy Note 9
I am using AndroidDeviceNames library in the banking app and found a problem: In the DeviceName class the getDeviceInfo() function uses the following code:
try {
return new DeviceInfo(new JSONObject(savedJson));
}
catch (Exception e) {
e.printStackTrace();
}
In this section of code, printStackTrace() outputs all exceptions to the console, even in the release build of the app. This behavior reduces the security of the application. In addition, stack trace in the console always catches the eye and irritates.
If the library can perform its functions successfully without annoying stack trace in the console, then you don't need to output extra information to the console. If you need to get this information when developing the library, then it is better to run printStackTrace() in the library version only for the developers of the library itself. To do this, you can use Timber library or your custom logger.
Please fix the specified problem.
Faced this too.