Search code examples
androidloggingreportingarchiveinstabug

How can I know when InstaBug is being called, so I can make a archive


I have some log files in my application, and I want to make a zip file with this logs, and send it via Instabug, when I shake my phone and press on "Report a Bug" or "Send Feedback".

This is the code from my Application:

  Instabug.initialize(this)
            .setAnnotationActivityClass(InstabugAnnotationActivity.class)
            .setShowIntroDialog(true, PSTimelineActivity.class)
            .enableEmailField(true,false)
            .setEnableOverflowMenuItem(true)
            .setDebugEnabled(true)
            .setBugHeaderText("Error")
            .attachFileAtLocation(Environment.getExternalStorageDirectory() + "/Passenger/log.zip");

As you can see, I select the file that should be attached, but I also need to make that file from my log file, just after I shook the phone (so it will take the latest logs), and before pressing any of the 2 buttons to report. I have the archive function, I just don't know where I could put it so this would work. Any ideeas?


Solution

  • I initialised Instabug like this:

    Instabug.initialize(this)
                .setAnnotationActivityClass(InstabugAnnotationActivity.class)
                .setShowIntroDialog(true, PSTimelineActivity.class)
                .enableEmailField(true,false)
                .setEnableOverflowMenuItem(true)
                .setDebugEnabled(true)
                .setBugHeaderText("Error")
                .setPreSendingRunnable(new Runnable() {
                    @Override
                    public void run() {
                        String[] files = new String[2];
                        files[0] = Environment.getExternalStorageDirectory() + "/Passenger/passenger_log.txt";
                        files[1] = Environment.getExternalStorageDirectory() + "/Passenger/passenger_log2.txt";
                        Compress compress = new Compress(files, Environment.getExternalStorageDirectory() + "/Passenger/log.zip");
                        compress.zip(new CrudStateCallback() {
                            @Override
                            public void onResponse(String string) {
                                Log.i("", "ended making the archive");
                            }
                        });
                    }
                })
                .attachFileAtLocation(Environment.getExternalStorageDirectory() + "/Passenger/log.zip");
    

    Following Hassan Ibraheem's advice, and now I create the .zip in the preSendingRunnable.