Skip to content

Instantly share code, notes, and snippets.

@lokeshsuryan
Created September 9, 2021 05:33
Show Gist options
  • Save lokeshsuryan/dcc56ca26b41c4d4f4aac33d58f35cf2 to your computer and use it in GitHub Desktop.
Save lokeshsuryan/dcc56ca26b41c4d4f4aac33d58f35cf2 to your computer and use it in GitHub Desktop.
package com.hms.crashkitharmony.slice;
import com.hms.crashkitharmony.ResourceTable;
import com.huawei.agconnect.crash.AGConnectCrash;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Button;
import ohos.agp.components.Component;
import ohos.hiviewdfx.HiLog;
import ohos.hiviewdfx.HiLogLabel;
public class MainAbilitySlice extends AbilitySlice {
HiLogLabel LABEL_LOG;
@Override
public void onStart(Intent intent) {
super.onStart(intent);
super.setUIContent(ResourceTable.Layout_ability_main);
LABEL_LOG = new HiLogLabel(HiLog.LOG_APP, 0x00201, "Main_ability");
Button button = (Button) findComponentById(ResourceTable.Id_btn_get_crash);
Button arithmeticCrashButton = (Button) findComponentById(ResourceTable.Id_btn_arithmetic_crash);
button.setClickedListener(component -> AGConnectCrash.getInstance().testIt(MainAbilitySlice.this));
arithmeticCrashButton.setClickedListener(component -> {
AGConnectCrash.getInstance().setCustomKey("intkey",1234);
AGConnectCrash.getInstance().setCustomKey("floatKey",2.5f);
AGConnectCrash.getInstance().setCustomKey("doubleKey",12.3456);
AGConnectCrash.getInstance().setCustomKey("stringKey","qwerty");
AGConnectCrash.getInstance().setUserId("absd");
AGConnectCrash.getInstance().log(HiLog.FATAL,"This User generated crash FATAL");
AGConnectCrash.getInstance().log(HiLog.ERROR,"This User generated crash ERROR");
AGConnectCrash.getInstance().log(HiLog.INFO,"This User generated crash INFO");
AGConnectCrash.getInstance().log(HiLog.LOG_APP,"This User generated crash LOG_APP");
AGConnectCrash.getInstance().log(HiLog.WARN,"This User generated crash WARN");
AGConnectCrash.getInstance().log(HiLog.DEBUG,"This User generated crash DEBUG");
AGConnectCrash.getInstance().log("This User generated crash without crash level");
int divisor=0;
int value=100;
int result=value/divisor;
HiLog.info(LABEL_LOG, "result: " +result);
});
}
@Override
public void onActive() {
super.onActive();
}
@Override
public void onForeground(Intent intent) {
super.onForeground(intent);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment