Search code examples
javaandroidarraysparcelable

How to get the keys from an object that seems to be matched dynamically. JAVA parcelable


I am having issues resolving this object it seems to be made completely out of a string then dynamically being matched to its key. if i try toString() this object it comes back with only the values(no keys) separated by a space. this is a SignalStrength java class. any help would be appreciated. The reason I am looking for the keys is the on particular phones the indexes seem to be different. enter image description here


Solution

  • The SignalStrength class (source code) has about half its field getters annotated with @hide. This means they are not publicly accessible in the SDK with a get() like the other fields, hence android studio will not show those methods.

    You have 2 options

    1. Use toString() which provides values for all fields, and split it so you can access the values by index, like you are already doing.

    2. Get the field values by reflection. Example

      Field field = null;
      try {
          field = SignalStrength.class.getDeclaredField("mLteRssnr");
          if (field.getType().isAssignableFrom(int.class)) {
              field.setAccessible(true);
              int lteRssnr = (int) field.get(signalStrength); // pass the instance of SignalStrength here.
      
          }
      } catch (NoSuchFieldException e) {
          e.printStackTrace();
      }