Thursday 26 March 2015

Android Remote Crash

 We can get crash data (stack traces) from Android application when working on our own device being retrieved by cable, But how to get the crash report from any instance of  app running on remote. This Android tutorial helps you to track the uncatched exception from remote device by letting the users to provide the users feedback along with the following details. All the information are generated into a PDF file and attached and send to your email (Developers mail).
  • Report collected date and time
  • Thread name, Exception name
  • App information like which version of your app is the crashed user using
  • The package name
  •  Device locale, Device model, Android version, Board, Host, Id, Product, Type
  • Memory info like Total memory, Available memory
  • And the Stack trace
 The following steps make you to understand what happen while an uncatched exception occurs in app and the steps to be followed:
  • Attach the library project to the app.
  • Initially we need to register the ExceptionReporter by passing the context of the activity before the super.onCreate(savedInstanceState); method.                                                                                                                                               protected void onCreate(Bundle savedInstanceState) {
            ExceptionReporter reporter = ExceptionReporter.register(this);
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            EditText sd = (EditText) findViewById(R.id.se);
        }
  • Running the app containing uncatched exception. eg : In XML i have a TextView declared and in JAVA i am referring TextView as EditText (EditText sd = (EditText) findViewById(R.id.textview);) this which will throw a Class cast exception.
  • When an uncaught exception is triggered the reporter creates a notification prompting the users that the app has been crashed and to help fixing the error by sending an error report to the developer.
  • The user decides to send the crash report or cancel the report.
  • If he decides to send report by clicking OK button all the above mentioned information are collected and put into a PDF file and saved externally in a directory named CrashReport and send to developers mail   
I libs i have used
  1. droidText.0.2.jar --> for generating PDF file
  2. mail.jar, additionnal.jar, activation.jar --> for attaching PDF and sending mail 
Note : Don't forget to add permission to the manifest of your app
  1.  <uses-permission android:name="android.permission.INTERNET" />
  2.  <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
  3. <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
The snap shots favors you to get better understanding :

App crashed and Notification appears:




Dialog that prompts users to enter message and click OK to send mail to developer:
All the PDF generation data gathering and mail sending are done in background.
You can use this features in your app. You can find the whole source code here
happy coding :) Please provide your valuable feedback.



1 comment: