This entry has been cross-posted in Codolution’s blog.
Let’s assume you have got a great Android app, how do you go about diagnosing problems users have with it? One big problem with mobile apps is the fact that it is gone out of your hands and you can’t see what’s happening when things go wrong.
Ideally, you would ask the user to send you some logs, but it is not as easy as it should be. Some time ago you could install an app that would read logs for you, but in a fairly recent versions of Android they can only see their own logs which is not very useful. You could ask users to root their device, or install developer toolkit and use ADB. Good luck trying. This is when a simple diagnostic tools could be helpful, if it allowed users to send your application’s logs back to you. Please meet diagnostic-tools.
Here you have a jar file you should to your project, which will give you a LogCollector. This class can read application logs and send them in an email with some information about the runtime environment. It actually doesn’t send email, it prepares it and lets user decide how to send it. Give it a try by installing the demo app or building it from source code.
What you need to do is (refer to the demo app if something is not clear):
Add a provider as shown below to your application. This is needed by FileProvider to share the log file with the email sending app as an attachment.
Add the XML file mentioned in the configuration above, which specifies the path for the files exported by this provider.
And finally, when you want to send logs, call the log collector.
mLogCollector.sendLogs("firstname.lastname@example.org", "Error Log", "Hey there, here is your log!",
"Some extra information, just because you wanted.",
Just one more thing that could be useful: If you are lucky enough to spot the issue and fix it, you go ahead and upload a new version, but there is no guarantee users will opt-in to your fix. One thing that can help with that is a kill switch. Using the kill switch you can remotely disable particular versions of your app and force users to upgrade to the latest. I’d recommend you to have at least a very basic kill switch from day 1, you never know when you are going to use it.
Credits: I have borrowed some code from https://code.google.com/p/android-log-collector/.