Android has, from ICS onwards (I think) provided the ability for a user to capture the system state, and then send or share the captured data with whomever they wish. See What does it mean with bug report captured in android tablet?
The captured data includes a screenshot, list of running processes, Logcat contents, active threads for each process, etc.
This is fantastically useful, but triggering it seems to involve the user pressing funny key combinations (Power + VolumeUp + VolumeDown) or enabling Developer mode and choosing specific options from there (Take bug report, Power menu bug reports).
Is there a way I can trigger this from my own code, so that I can offer my users a simple menu option to capture a bug report?
Reading up on the link that you have posted – What does it mean with bug report captured in android tablet?
The [answer] marked as correct says
bugmailer.sh in the
system/bin does the reporting.
So, in theory if you could detect an app crash using any of these methods, then you could execute your own copy of
bugmailer.sh in the sdcard and get a report.
However, you will realize that this will obviously work only for rooted phones as you read the source.
The easier way would be to open the
Developer options and have a system overlay window pointing at what they should click. This would be the only user friendly solution for non rooted phones.
You can open the
Developer options using
startActivity(new Intent( Settings.ACTION_APPLICATION_DEVELOPMENT_SETTINGS));
For further reference.
I have found a way but it requires root.
What responsible of bug report is dumpstate.c.
usage: dumpstate [-b soundfile] [-e soundfile] [-o file [-d] [-p] [-z]] [-s] [-q ] -o: write to file (instead of stdout)
-d: append date to filename (requires -o)
-z: gzip output (requires -o)
-p: capture screenshot to filename.png (requires -o)
-s: write output to control socket (for init)
-b: play sound file instead of vibrate, at beginning of job
-e: play sound file instead of vibrate, at end of job
-q: disable vibrate
-B: send broadcast when finished (requires -o and -p)
dumpstate called with
-B parameter, it broadcasts
"android.intent.action.BUGREPORT_FINISHED" after that BugreportReceiver handles warning the user and sharing the result.
I haven’t try it but, everyone who has root privileges can call
dumpstate -o dump -p -B
to trigger it.
As far as I know, users get the option to report a crash to the Google play.
There are sites that offer this functionality though, https://www.bugsense.com/ for example is easily integrated and also offers
graddle/maven support. By using sites like these, you are sharing your data with them most likely though. That will be a trade of you have to make.
Is there a way I can trigger this from my own code, so that I can
offer my users a simple menu option to capture a bug report?
There is a library called ACRA (Application Crash Reports for Android ) which allows you to send crash reports to any destinations from your own code. Developer configurable user interaction such as silent reports, Toast notification, status bar notification + dialog or direct dialog are available.
You can add your own log file extracts as well as logcat, eventlog or radiolog to reports. It’s a very useful tool for crash data analysis and reports management for developers.