Wednesday, May 1, 2013

Android Crash report using ACRA ,BugSense and Parse.com

Android Crash report using ACRA ,BugSense and Parse.com

In my previous post I have described how to integrate ACRA and goolge form in order to get crash reports from Android application. Google as published new version of their form so it can no longer be used as ACRA report storage (more details can be found here). If you want to use ACRA and do not have your own server you need to choose other backends.
I will present two options:
1. Using BugSense.
2. Using Parse.com.

Using BugSense

BugSense provide tools for monitor your mobile application. BugSense has crash report similar to ACRA but BugSense web server can also get ACRA reports without the need to download or use additional SDKs.

In order to integrate ACRA abd BugSense:
1. Open account in BugSense.
2. Define your application in BugSense dashboard
3. Create Android application class and add it to your project Manifest file.

 @ReportsCrashes(formUri = "http://www.bugsense.com/api/acra?api_key=YOUR_API_KEY", formKey="")  
 public class MyApp extends Application  
 {  
  @Override  
  public void onCreate() {  
  // TODO Auto-generated method stub  
  super.onCreate();   
  ACRA.init(this);  
  }  

Using Parse.com

Parse  provides backend services for mobile and web application it also has push notifications services. It free addition provide about 1M requests per month. I will use Parse in order to store ACRA crash reports.

Integrating Parse and ACRA:
1. Register to Parse and download the SDK.
2. Create application in Parse website and get the application,client keys.
3. Add the SDK to you application Lib directory and add it to build path.
4. Verify that you have the following permissions in you Manifest file

 <uses-permission android:name="android.permission.INTERNET"/>  
 <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>  

5. You need to get Application key and Client key for your application (look at Parse application dashboard settings)
6. Create Android application class and add it to your project Manifest file. 
7. Initialize parse sdk, ACRA and register report sender in the application class onCreate method. 

 import org.acra.ACRA;  
 import org.acra.ErrorReporter;  
 import org.acra.annotation.ReportsCrashes;  
 import android.app.Application;  
 import com.parse.Parse;  
 import com.parse.ParseObject;  
    
 @ReportsCrashes( formKey="")  
 public class MyApp extends Application   
 {  
      @Override  
      public void onCreate() {  
           // TODO Auto-generated method stub  
           super.onCreate();  
           Parse.initialize(this, Application key,Client key);   
           ACRA.init(this);  
           ErrorReporter.getInstance().setReportSender(new LocalSender(this));  
      }    
 }  

7. The following code implements ACRA report sender that will send the crash report file to Parse.com. The code uses ParseFile and ParseObject (details).

 import java.io.ByteArrayOutputStream;  

 public class LocalSender implements ReportSender {  
      private final Map<ReportField, String> mMapping = new HashMap<ReportField, String>() ;  
      private FileOutputStream crashReport = null;  
      private Context ctx;  
      public LocalSender(Context ct) {  
           ctx = ct;  
      }  
      public void send(CrashReportData report) throws ReportSenderException {  
           final Map<String, String> finalReport = remap(report);  
           ByteArrayOutputStream buf = new ByteArrayOutputStream();  
           Log.i("hcsh","Report send");  
           try {  
                Set set = finalReport.entrySet();  
                Iterator i = set.iterator();  
                String tmp;  
                while (i.hasNext()) {  
                     Map.Entry<String,String> me = (Map.Entry) i.next();  
                     tmp = "[" + me.getKey() + "]=" + me.getValue();  
                     buf.write(tmp.getBytes());  
                }  
                ParseFile myFile = new ParseFile("crash.txt", buf.toByteArray());  
                myFile.save();  
                ParseObject jobApplication = new ParseObject("AppCrash");  
                jobApplication.put("MyCrash", "Test App");  
                jobApplication.put("applicantResumeFile", myFile);  
                try {  
                     jobApplication.save();  
                } catch (ParseException e) {  
                     // TODO Auto-generated catch block  
                     e.printStackTrace();  
                }  
           }catch (FileNotFoundException e) {  
                Log.e("TAG", "IO ERROR",e);  
           }  
           catch (IOException e) {  
                Log.e("TAG", "IO ERROR",e);  
           } catch (ParseException e) {  
                // TODO Auto-generated catch block  
                e.printStackTrace();  
           }  
 }  
 private Map<String, String> remap(Map<ReportField, String> report) {  
      ReportField[] fields = ACRA.getConfig().customReportContent();  
      if (fields.length == 0) {  
           fields = ACRA.DEFAULT_REPORT_FIELDS;  
      }  
      final Map<String, String> finalReport = new HashMap<String, String>(  
                report.size());  
      for (ReportField field : fields) {  
           if (mMapping == null || mMapping.get(field) == null) {  
                finalReport.put(field.toString(), report.get(field));  
           } else {  
                finalReport.put(mMapping.get(field), report.get(field));  
           }  
      }  
      return finalReport;  
 }  
 }  

8. In case of crash the result on Parse dashboard will be :




Each crash will be display in separate row with report time stamp.

35 comments:

  1. parse features measures the actual usage of the app: it minutely views your app and API request data through the Parse dashboard. The developer can see real-time analytics on API requests based dashboard on REST verbs, device type, and Parse class being accessed.

    ReplyDelete
  2. Because Parse shutdown I've migrated my application to www.back4app.com Can someone detail me how to proceed regarding the push notifications?

    ReplyDelete
  3. This is really very interesting. This blog contain too much information about parse android app development.

    ReplyDelete
  4. Thank you for posting this beneficial content material. You provided another one great article in robotics projects chennai. I hope this information may change my business carrier.I can remember these things whenever taking the decision in raspberry pi projects chnenai.

    ReplyDelete
  5. Your good knowledge and kindness in playing with all the pieces were very useful. I don’t know what I would have done if I had not encountered such a step like this.
    Data Science Training in Chennai
    Data science training in bangalore
    Data science online training
    Data science training in pune

    ReplyDelete
  6. Good Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge as updated one, keep blogging.
    Devops training in Chennai
    Devops training in Bangalore
    Devops Online training
    Devops training in Pune

    ReplyDelete
  7. Thanks for sharing this valuable information to our vision Digital Marketing Courses in Mumbai

    ReplyDelete
  8. Inspiring writings and I greatly admired what you have to say , I hope you continue to provide new ideas for us all and greetings success always for you..Keep update more information..
    java training in annanagar | java training in chennai

    java training in marathahalli | java training in btm layout

    java training in rajaji nagar | java training in jayanagar

    java training in chennai

    ReplyDelete
  9. I think this is a great site to post and I have read most of contents and I found it useful for my Career .Thanks for the useful information. For any information or Queries Comment like and share it.

    PMP Training Abu Dhabi

    GDPR Training in Hyderabad

    GDPR Training in Pune

    ReplyDelete
  10. This is an awesome post.Really very informative and creative contents. These concept is a good way to enhance the knowledge.I like it and help me to development very well.Thank you for this brief explanation and very nice information.Well, got a good knowledge.
    python training in velachery
    python training institute in chennai

    ReplyDelete
  11. Thanks for the informative article. This is one of the best resources I have found in quite some time. Nicely written and great info. I really cannot thank you enough for sharing.
    DevOps online Training
    Best Devops Training institute in Chennai

    ReplyDelete
  12. Hello. This post couldn’t be written any better! Reading this post reminds me of my previous roommate.
    nebosh course in chennai

    ReplyDelete
  13. This is a nice article here with some useful tips for those who are not used-to comment that frequently. Thanks for this helpful information I agree with all points you have given to us. I will follow all of them.

    angularjs online Training

    angularjs Training in marathahalli

    angularjs interview questions and answers

    angularjs Training in bangalore

    angularjs Training in bangalore

    angularjs online Training

    ReplyDelete
  14. Howdy, would you mind letting me know which web host you’re utilizing? I’ve loaded your blog in 3 completely different web browsers, and I must say this blog loads a lot quicker than most. Can you suggest a good internet hosting provider at a reasonable price?
    iosh course in chennai

    ReplyDelete
  15. Thanks for providing such helpful information. I will definitely follow this steps while developing android applications.

    ReplyDelete
  16. Good Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge as updated one, keep blogging.
    Devops Training in Electronic City

    ReplyDelete
  17. I read your blog , this is very attractive and impressive blog .

    ReplyDelete
  18. I read this post two times, I like it so much, please try to keep posting & Let me introduce other material that may be good for our community.

    ReplyDelete
  19. I surely acquiring more difficulties from each surprisingly more little bit of it
    data scientist training and placement

    ReplyDelete
  20. I really enjoyed reading this post, big fan. Keep up the good work and please tell me when can you publish more articles or where can I read more on the subject?
    data science institutes in hyderabad

    ReplyDelete
  21. Really nice and interesting post. I was looking for this kind of information and enjoyed reading this one.
    data analytics course in hyderabad

    ReplyDelete
  22. Extremely overall quite fascinating post. I was searching for this sort of data and delighted in perusing this one. Continue posting. A debt of gratitude is in order for sharing.business analytics course in rohtak

    ReplyDelete
  23. Your blog has a lot of intriguing content, especially the discussions. I assume that not just myself is finding this place to be quite enjoyable based on the numerous comments on your posts. Continue your wonderful work. Click here to Enroll in data science Training in Bhopal

    ReplyDelete