Skip to content

Commit

Permalink
fix(imei): add handle exception to get imei
Browse files Browse the repository at this point in the history
Signed-off-by: Ivan Del Pino <idelpino@teclib.com>
  • Loading branch information
Ivan Del Pino authored and ajsb85 committed Dec 14, 2018
1 parent be30217 commit 53e7ef4
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ protected void onCreate(Bundle savedInstanceState) {
ActivityCompat.requestPermissions(MainActivity.this,
new String[]{
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.READ_PHONE_STATE,
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.CAMERA,
},
Expand Down Expand Up @@ -65,6 +66,17 @@ public void onTaskError(Throwable error) {
Toast.makeText(MainActivity.this, "Inventory fail, check the log", Toast.LENGTH_SHORT).show();
}
});
inventoryTask.getJSON(new InventoryTask.OnTaskCompleted() {
@Override
public void onTaskSuccess(String data) {
Log.d(TAG, data);
}

@Override
public void onTaskError(Throwable error) {
Toast.makeText(MainActivity.this, "Error", Toast.LENGTH_SHORT).show();
}
});
}
});
}
Expand All @@ -78,7 +90,8 @@ public void onRequestPermissionsResult(int requestCode, String permissions[], in
if (grantResults.length > 0
&& grantResults[0] == PackageManager.PERMISSION_GRANTED
&& grantResults[1] == PackageManager.PERMISSION_GRANTED
&& grantResults[2] == PackageManager.PERMISSION_GRANTED) {
&& grantResults[2] == PackageManager.PERMISSION_GRANTED
&& grantResults[3] == PackageManager.PERMISSION_GRANTED) {
}
}
}
Expand Down
30 changes: 17 additions & 13 deletions inventory/src/main/java/org/flyve/inventory/categories/Modems.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,23 +83,27 @@ public Modems(Context xCtx) {
*/
public ArrayList<String> getIMEI() {
ArrayList<String> imeiList = new ArrayList<>();
TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
SubscriptionManager subscriptionManager = (SubscriptionManager) context.getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
assert subscriptionManager != null;
List<SubscriptionInfo> multipleSim = subscriptionManager.getActiveSubscriptionInfoList();
if (multipleSim != null && multipleSim.size() > 0) {
for (int i = 0; i < multipleSim.size(); i++) {
if (telephonyManager != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
imeiList.add(telephonyManager.getDeviceId(i));
try {
TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
SubscriptionManager subscriptionManager = (SubscriptionManager) context.getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
assert subscriptionManager != null;
List<SubscriptionInfo> multipleSim = subscriptionManager.getActiveSubscriptionInfoList();
if (multipleSim != null && multipleSim.size() > 0) {
for (int i = 0; i < multipleSim.size(); i++) {
if (telephonyManager != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
imeiList.add(telephonyManager.getDeviceId(i));
}
}
} else {
imeiList.add("N/A");
}
} else {
imeiList.add("N/A");
String imei = telephonyManager.getDeviceId();
imeiList.add(imei != null ? imei : "N/A");
}
} else {
String imei = telephonyManager.getDeviceId();
imeiList.add(imei != null ? imei : "N/A");
} catch (Exception ex) {
imeiList.add("N/A");
}
return imeiList;
}
Expand Down

0 comments on commit 53e7ef4

Please sign in to comment.