1

I have a networkStateReceiver, that checks if I have internet or not. If I do, I reinitiate instabug, if not, I want to deactivate. How can I do that? I tried just setting it as null, but it doesn't work.

if(haveConnectedMobile || haveConnectedWifi){
            //TODO will need to make a queue, and go through all that queue
            PSLocationCenter.getInstance().initInstabug();
        }else{
            PSLocationCenter.getInstance().instabug = null;
        }

This is my init:

public void initInstabug() {
    String[] feedbackArray = getResources().getStringArray(R.array.feedback);
    String randomStr = feedbackArray[new Random().nextInt(feedbackArray.length)];
    Instabug.DEBUG = true;
    instabug = Instabug.initialize(this)
            .setAnnotationActivityClass(InstabugAnnotationActivity.class)
            .setShowIntroDialog(true, PSTimelineActivity.class)
            .enableEmailField(true, false)
            .setEnableOverflowMenuItem(true)
            .setDebugEnabled(true)
            .setCommentRequired(true)
            .setPostFeedbackMessage(randomStr)
            .setPostBugReportMessage(randomStr) //TODO will be the post report message, random from array
            .setCommentFieldHint("Please describe what went wrong")
            .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");
}
rosu alin
  • 5,674
  • 11
  • 69
  • 150

2 Answers2

2

You can use this code to disable Instabug automatic invocation:

Instabug.getInstance().setInvocationEvent(IBGInvocationEvent.IBGInvocationEventNone)

This way it won't be invoked automatically. This will only affect the next Activity though (not the current one). You may force to stop and restart all listeners by calling onPause and onResume on the current Activity. (We may address that soon though, so that such changes are applied on the currently running Activity).

Don't forget to also enable the shake invocation event when internet access is restored.

Please keep in mind that Instabug SDK already caches all reports and will re-attempt to send them on next app launch until they're uploaded successfully.

Hassan Ibraheem
  • 2,329
  • 1
  • 17
  • 23
  • I tried IBGInvocationEventNone, but it did not work. Surely because I did not restart the activity. Although this is not needed anymore, because like you said, if there is no internet it SHOULD send the reports after the internet is back. I'm saying SHOULD, cause I tried it, and on Iphone it did sent the report when I activated the internet, on Android it did not. PS: I am using this version, so it should take the latest, right?: compile 'com.instabug.library:instabugsupport:1+' – rosu alin Jul 03 '15 at 11:21
  • Sorry, just read your answer again. It will try to send on the next app launch? Meaning that in order to send the report, I need to force close the app and start it again? Why not on chancing an Activity? – rosu alin Jul 03 '15 at 11:22
  • No need to force close the app. If you call onPause then onResume in the current activity, the SDK will restart any listeners with the new configuration. Can you send me an email to contactus@instabug.com regarding the network issue? – Hassan Ibraheem Jul 03 '15 at 11:59
  • Apparently there is no need. I checked now in Instabug and I saw the ones that I sent offline. but They only appeared today. It wasn't as fast as the online ones. Thank you a lot for your help – rosu alin Jul 03 '15 at 12:35
0

Just wanted to post the updated answer.

The newer SDK has changed the name and now you can disable it by the following code:

Instabug.changeInvocationEvent(InstabugInvocationEvent.NONE)

Notice, if you want to disable it for entire application, just call this method in your Application class

J.Doe
  • 1
  • 1