Skill Level: Intermediate
One of our recommended practices is to set up a way to obtain SDK debug information from your app to help when getting technical support. Specifically, itâ€™s very common for our support team to request mobile user ID and SDK versions, though there are a number of other items you may want to include in a debug screen such as OS version and platform, build version of your app, channel ID, app key and so on. If you have this information easily available from devices in the field, it becomes significantly easier to resolve problems. Most customers prefer to keep this information hidden until itâ€™s needed. We recommend that as well. Thus the question arises: how can one make a secret trigger that can be used to report SDK information, but make it relatively easy to access when needed. This is one possible solution. You may want to use a different way to trigger the way to open the screen, and consider issues with accessibility.
Not what youâ€™re looking for? Check out all our available tutorials for mobile app messaging here.
Setting up a secret trigger on Android to display SDK debug information
Changes to the sample app
We will make these changes to the sample app. Changes to your app will be similar.
Decide where youâ€™ll trigger from
You will need to find an appropriate place in your app from which a user invokes the trigger. Often this is the configuration screen, but if you have a lot of elements on that screen, another view may be preferable. Itâ€™s best if itâ€™s a screen where youâ€™re not already collecting touch events.
A view which has a text entry field offers slightly more security than one which doesnâ€™t. We will describe why further on.
In our case, we will be adding the event to the â€śSend User Attributesâ€ť screen in the sample app.
Add the changes
To AttributeSampleActivity, add the following variables:
The pattern instance variable represents the number of touches on the screen that must occur for the event to be triggered. In this case, we require detection of one finger touching the screen, then two, then three, then four. After that one finger must be lifted (leaving three) and then another finger must be lifted (leaving two). Next an additional finger must touch the screen (for a total of three). Finally, one finger must be lifted, leaving two. When that happens, the event will be triggered. Any deviation from the pattern resets it back to the beginning.
We strongly recommend you change the sample pattern. You might want to use a different pattern for each app, or even each major revision of the app. Remember, however, that your support reps will need to be able to tell people how to trigger the diagnostic event. If itâ€™s too complicated Â (or if some of your devices donâ€™t support detection of four touches on a screen) you may need to adjust it.
Add these methods
Add the following three methods to the bottom of the Activity (AttributeSampleActivity in the sample):
The action that is executed when the event is triggered is in showDebugScreen. In the case of the sample app, it already has a screen which reports mobile user ID, channel ID and app key. If the touch events are appropriately triggered, we invoke it.
Note the test for attributeKey in showDebugScreen. In our example, the sample app will never invoke an action (even if the trigger touches happen) unless the â€śkeyâ€ť field contains the value â€śAttributesActivityâ€ť. We chose that value because itâ€™s already present in the class, so it will be reused from the class pool. Doing so obscures the code slightly from those who decompile the class. Similarly, you might want to change method names so people who decompile will not think to look further, or change how the pattern is stored (perhaps by encoding it or constructing it via computation). Ultimately, because itâ€™s Java bytecode in an APK, your code may be extracted by anyone who installs your app. Because of this, keep passwords out of your diagnostics.
Another option (rather than opening a screen) is to create an email message addressed to your support group. In general, this is done by creating an Intent:
Need more help? Check out all of our available tutorials for mobile app messaging here.