-3

I am trying to log the following in Android Java:

    Log.i("Build.VERSION.SDK_INT", Build.VERSION.SDK_INT.toString());
    Log.i("Build.VERSION_CODES.M", Build.VERSION_CODES.M.toString());
    Log.i("Build.VERSION_CODES.O", Build.VERSION_CODES.O.toString());
    Log.i("getReactApplicationContext().checkCallingOrSelfPermission(Manifest.permission.READ_SMS", getReactApplicationContext().checkCallingOrSelfPermission(Manifest.permission.READ_SMS).toString());
    Log.i("getReactApplicationContext().checkCallingOrSelfPermission(Manifest.permission.READ_PHONE_NUMBERS)", getReactApplicationContext().checkCallingOrSelfPermission(Manifest.permission.READ_PHONE_NUMBERS).toString());
    Log.i("getReactApplicationContext().getSystemService(Context.TELEPHONY_SERVICE)", getReactApplicationContext().getSystemService(Context.TELEPHONY_SERVICE).toString());
    Log.i("Build.VERSION_CODES.O", Build.VERSION_CODES.O.toString());

But I get the error error: int cannot be dereferenced on every line.

How can I log these objects in logcat?

Mr. Robot
  • 1,334
  • 6
  • 27
  • 79
  • Thanks, but is every one of these values an integer? My question is how can I log these objects? – Mr. Robot Mar 04 '21 at 18:10
  • Look at the top answer to the question I referenced, it explains why you can't call methods on primitives and even gives an alternative. – Henry Twist Mar 04 '21 at 18:13
  • There is an error: " The logging tag can be at most 23 characters, was 86 (getReactApplicationContext().checkCallingOrSelfPermission(Manifest.permission.READ_SMS)" – Roie Shlosberg Mar 04 '21 at 19:00
  • 1
    https://stackoverflow.com/questions/28168622/the-logging-tag-can-be-at-most-23-characters – Zoe Mar 04 '21 at 19:01

1 Answers1

1

Because Build.VERSION.SDK_INT and other are integers. They are primitives and do not have toString() function. If you want to convert int to String you can use String.valueOf().

Log.i("Build.VERSION.SDK_INT", String.valueOf(Build.VERSION.SDK_INT));

Or sometimes it is easier to use string concatenation. For example:

Log.i("Build.VERSION.SDK_INT", "" + Build.VERSION.SDK_INT);

I mostly use second method for debugging purposes.

artman
  • 632
  • 2
  • 7
  • 16