我有一个networkStateReceiver,它检查我是否有互联网。
如果这样做,我将重新启动instabug,如果没有,我想将其停用。我怎样才能做到这一点?
我尝试将其设置为null,但是它不起作用。
if(haveConnectedMobile || haveConnectedWifi){
//TODO will need to make a queue, and go through all that queue
PSLocationCenter.getInstance().initInstabug();
}else{
PSLocationCenter.getInstance().instabug = null;
}
这是我的初始化:
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");
}
最佳答案
您可以使用以下代码禁用Instabug自动调用:
Instabug.getInstance().setInvocationEvent(IBGInvocationEvent.IBGInvocationEventNone)
这样,将不会自动调用它。不过,这只会影响下一个活动(而不影响当前活动)。您可以通过在当前活动上调用
onPause
和onResume
来强制停止并重新启动所有侦听器。 (不过,我们可能会尽快解决,以便将此类更改应用于当前运行的Activity)。恢复互联网访问时,请不要忘记也启用震动调用事件。
请记住,Instabug SDK已经缓存了所有报告,并将在下次启动应用程序时重新尝试将它们发送,直到它们成功上传为止。