Capture error and display a dialog to send report on Android

3

Hi, I have created an app for android and it works correctly, but sometimes it finds errors and a message to force close and send report, I noticed that in applications like facebook or whatsapp apart from showing the dialog with the buttons to force Close and send report appears the wait button, how could I create something similar in my app when I see an error?

Attached sample image:

    
asked by Gustavo Piris 21.05.2016 в 20:29
source

2 answers

1

An option to create something similar would be a DialogFragment, example:

public class DialogFragment extends DialogFragment {
   @Override
   public Dialog onCreateDialog(Bundle savedInstanceState) {
      AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
      builder.setPositiveButton("Continuar", new DialogInterface.OnClickListener() {
         public void onClick(DialogInterface dialog, int id) {
            toast.makeText(this,"Continua",Toast.LENTH_SHORT).show();
         }
      })
      .setNegativeButton("Forzar cierre", new DialogInterface.OnClickListener() {
         public void onClick(DialogInterface dialog, int id) {
toast.makeText(this,"Cierra",Toast.LENTH_SHORT).show()
            finish();
         });
         return builder.create();
      }
   }
}

But that dialogue that samples are actually generated by the operating system, is something called ANR (Application Not Responding)

    
answered by 21.05.2016 в 22:57
1

Try the library ACRA It seems easy to implement and does not require 100% to have a server, to receive the reports, you can send it by email More information in your documentation

Example using a proprietary server to receive reports:

@ReportsCrashes(formUri = "http://yourserver.com/yourscript",
                formUriBasicAuthLogin = "yourlogin", // optional
                formUriBasicAuthPassword = "y0uRpa$$w0rd", // optional
                mode = ReportingInteractionMode.TOAST,
                resToastText = R.string.crash_toast_text)
public class MyApplication extends Application {
...

To show an Error dialog

@ReportsCrashes(formUri = "http://yourserver.com/yourscript",
                mode = ReportingInteractionMode.DIALOG,
                resToastText = R.string.crash_toast_text, // optional, displayed as soon as the crash occurs, before collecting data which can take a few seconds
                resDialogText = R.string.crash_dialog_text,
                resDialogIcon = android.R.drawable.ic_dialog_info, //optional. default is a warning sign
                resDialogTitle = R.string.crash_dialog_title, // optional. default is your application name
                resDialogCommentPrompt = R.string.crash_dialog_comment_prompt, // optional. When defined, adds a user text field input with this text resource as a label
                resDialogEmailPrompt = R.string.crash_user_email_label, // optional. When defined, adds a user email text entry with this text resource as label. The email address will be populated from SharedPreferences and will be provided as an ACRA field if configured.
                resDialogOkToast = R.string.crash_dialog_ok_toast // optional. displays a Toast message when the user accepts to send a report.
                resDialogTheme = R.style.AppTheme_Dialog, //optional. default is Theme.Dialog
                )
public class MyApplication extends Application {
...
    
answered by 22.05.2016 в 09:26