Bugly.testCrash(Bugly.JAVA_CRASH); // 模拟 Java 异常Bugly.testCrash(Bugly.NATIVE_CRASH); // 模拟 Native 异常

Bugly.testCrash(Bugly.ANR_CRASH); // 模拟 ANR
private void testANR(){try {Thread.sleep(30000);} catch (Exception e){// do nothing}}


private void testJavaCatchError(){String content = "a illegal string.";try {JSONObject jsonObject = new JSONObject(content);double price = jsonObject.getDouble("price");} catch (Throwable t) {Bugly.handleCatchException(Thread.currentThread(), t,"in test code for json parse fail.", content.getBytes(), true);}}
Bugly.postException(4, "testErrorType", "testErrorMsg", "testStack", null);


private void costJobOne() {AppLaunchProxy.getAppLaunch().addTag("has_cost_job_one");AppLaunchProxy.getAppLaunch().spanStart("costJobOne", null);try {Thread.sleep(300);} catch (Throwable t) {Bugly.handleCatchException(Thread.currentThread(), t, "costJobOne sleep fail", null, true);}AppLaunchProxy.getAppLaunch().spanEnd("costJobOne");}private void finalJob() {AppLaunchProxy.getAppLaunch().reportAppFullLaunch();}


private void testLongLag() {showToast("测试长卡顿");sleep(200);callFunctionA();callFunctionB();}private void callFunctionA() {sleep(400);callFunctionB();}private void callFunctionB() {sleep(300);}private static void sleep(long timeInMs) {try {Thread.sleep(timeInMs);} catch (Throwable t) {Bugly.handleCatchException(Thread.currentThread(), t, "sleep", null, false);}}

public static void initBugly(Context context) {// 1. 初始化参数预构建,必需设置初始化参数String appID = "xxxxxxx"; // 【必需设置】在终端性能监控Pro 创建产品的appIDString appKey = "xxxxxxxxxxx"; // 【必需设置】在终端性能监控Pro 创建产品的appKeyBuglyBuilder builder = new BuglyBuilder(appID, appKey);......// 2. 开启Java内存详情build.addMonitor(BuglyMonitorName.MEMORY_JAVA_CEILING);// 3. 初始化,必需调用Bugly.init(context, builder);}




// 开启代理BuglyURLStreamHandlerFactory.init(okHttpClient);
// 关闭代理BuglyURLStreamHandlerFactory.reset();
OkHttpClient client = new OkHttpClient.Builder().eventListenerFactory(BuglyListenerFactory.getInstance()).build();


...buglyBuilder.addMonitor(BuglyMonitorName.TRAFFIC);buglyBuilder.addMonitor(BuglyMonitorName.TRAFFIC_DETAIL);...// 初始化Bugly SDKBugly.init(application, buglyBuilder);
CustomTrafficStatistic.getInstance().addHttpToQueue(SocketInfo socketInfo);
class SocketInfo {receivedBytes; // 收到多少字节sendBytes; // 发送了多少字节networkType; // 网络类型,WiFi流量填1, 5G流量填2, 无网络情况填3frontState; // 前后台状态,前台填1,后台填2host; // 域名,例如www.baidu.comstartTimeStamp; // 网络请求开始时间戳,精确到ms......}


...buglyBuilder.addMonitor(BuglyMonitorName.PAGE_LAUNCH); // 添加此语句...Bugly.init(context, builder);
/*** 标记 activity 启动过程中某个span的开始* @param activity* @param name, span名字* @param parentName, 父span的名字*/public void startSpan(Activity activity, String name, String parentName);/*** 标记 activity 启动过程中某个span的结束* @param activity* @param name span名字,需要匹配startSpan的参数*/public void endSpan(Activity activity, String name);/*** 用户自定义Activity启动结束时间点,会以调用该接口的时间作为Activity的启动结束时间* @param activity*/public void reportActivityFullLaunch(Activity activity);
@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);PageLaunchMonitor.getInstance().startSpan(this, "MemoryTracerTest", "");PageLaunchMonitor.getInstance().startSpan(this, "onCreate", "MemoryTracerTest");startMemoryTrace();PageLaunchMonitor.getInstance().endSpan(this, "onCreate");}@Overridepublic void onResume() {super.onResume();PageLaunchMonitor.getInstance().startSpan(this, "onResume", "MemoryTracerTest");reStartMemoryTrace();PageLaunchMonitor.getInstance().endSpan(this, "onResume");PageLaunchMonitor.getInstance().endSpan(this, "MemoryTracerTest");// 等页面加载完成之后,才调用 reportLaunchFinished 来定义Activity启动结束new Thread (new Runnable() {reportLaunchFinished();}).start();}private void reportLaunchFinished() {PageLaunchMonitor.getInstance().reportActivityFullLaunch(this);}

本页内容是否解决了您的问题?
You can also Contact sales or Submit a Ticket for help.
Help us improve! Rate your documentation experience in 5 mins.
文档反馈