Java Code Examples for com.tencent.bugly.crashreport.CrashReport#UserStrategy

The following examples show how to use com.tencent.bugly.crashreport.CrashReport#UserStrategy . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: InitializeService.java    From YCAudioPlayer with Apache License 2.0 6 votes vote down vote up
/**
 * 初始化腾讯bug管理平台
 */
private void initBugly() {
    /* Bugly SDK初始化
    * 参数1:上下文对象
    * 参数2:APPID,平台注册时得到,注意替换成你的appId
    * 参数3:是否开启调试模式,调试模式下会输出'CrashReport'tag的日志
    * 注意:如果您之前使用过Bugly SDK,请将以下这句注释掉。
    */
    CrashReport.UserStrategy strategy = new CrashReport.UserStrategy(getApplicationContext());
    // 设置版本号
    strategy.setAppVersion(AppUtils.getAppVersionName());
    // 设置版本名称
    String appPackageName = AppUtils.getAppPackageName();
    strategy.setAppPackageName(appPackageName);
    // 获取当前进程名
    String processName = AppToolUtils.getProcessName(android.os.Process.myPid());
    // 设置是否为上报进程
    strategy.setUploadProcess(processName == null || processName.equals(appPackageName));
    //Bugly会在启动20s后联网同步数据
    strategy.setAppReportDelay(20000);
    //正式版
    CrashReport.initCrashReport(getApplicationContext(), "521262bdd7", false, strategy);
}
 
Example 2
Source File: BaseApplication.java    From shinny-futures-android with GNU General Public License v3.0 6 votes vote down vote up
/**
 * date: 2019/6/18
 * author: chenli
 * description: 配置bugly
 */
private void initBugly(String BUGLY_KEY){
    CrashReport.UserStrategy strategy = new CrashReport.UserStrategy(sContext);
    strategy.setCrashHandleCallback(new CrashReport.CrashHandleCallback() {
        public Map<String, String> onCrashHandleStart(int crashType, String errorType,
                                                      String errorMessage, String errorStack) {
            JSONObject jsonObject = new JSONObject();
            try {
                jsonObject.put(AMP_EVENT_CRASH_TYPE, crashType);
                jsonObject.put(AMP_EVENT_ERROR_TYPE, errorType);
                jsonObject.put(AMP_EVENT_ERROR_MESSAGE, errorMessage);
                jsonObject.put(AMP_EVENT_ERROR_STACK, errorStack);
            } catch (JSONException e) {
                e.printStackTrace();
            }
            Amplitude.getInstance().logEventWrap(AMP_CRASH, jsonObject);
            LinkedHashMap<String, String> map = new LinkedHashMap<>();
            map.put("user-agent", sDataManager.USER_AGENT);
            return map;
        }
    });
    Beta.enableHotfix = false;
    Bugly.init(sContext, BUGLY_KEY, false, strategy);
}
 
Example 3
Source File: RongRTCApplication.java    From sealrtc-android with MIT License 6 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();
    Utils.init(this);
    // bugly 配置,查看对应崩溃日志。
    String processName = Utils.getCurProcessName(this);
    // 设置是否为上报进程
    CrashReport.UserStrategy strategy = new CrashReport.UserStrategy(this);
    strategy.setUploadProcess(processName.equals(getPackageName()));
    // 初始化Bugly
    CrashReport.initCrashReport(this, "3612cc23a8", false, strategy);
    if (getApplicationInfo().packageName.equals(Utils.getCurProcessName(this))) {
      try {
        RongIMClient.registerMessageType(RoomInfoMessage.class);
        RongIMClient.registerMessageType(WhiteBoardInfoMessage.class);
        RongIMClient.registerMessageType(RoomKickOffMessage.class);
      } catch (AnnotationNotFoundException e) {
        e.printStackTrace();
      }

      // 相芯SDK 初始化
      FURenderer.initFURenderer(this);
    }

    registerLifecycleCallbacks();
}
 
Example 4
Source File: MyApplication.java    From PicKing with Apache License 2.0 6 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();
    OkHttpClient okHttpClient = new OkHttpClient.Builder()
            .build();
    ImagePipelineConfig config = OkHttpImagePipelineConfigFactory.newBuilder(this, okHttpClient)
            .setMainDiskCacheConfig(getDiskCacheConfig())
            .setNetworkFetcher(new OkHttpNetworkFetcher(okHttpClient))
            .setDownsampleEnabled(true)
            .build();
    Fresco.initialize(this, config);

    Context context = getApplicationContext();
    String packageName = context.getPackageName();
    String processName = getProcessName(android.os.Process.myPid());
    CrashReport.UserStrategy strategy = new CrashReport.UserStrategy(context);
    strategy.setUploadProcess(processName == null || processName.equals(packageName));
    CrashReport.initCrashReport(getApplicationContext(), "0a6e92fb70", false, strategy);

    registerActivityLifecycleCallbacks(ActivityLifecycleHelper.build());
}
 
Example 5
Source File: AppApplication.java    From OpenHub with GNU General Public License v3.0 6 votes vote down vote up
private void initBugly(){

        Beta.initDelay = 6 * 1000;
        Beta.enableHotfix = false;
        Beta.canShowUpgradeActs.add(LoginActivity.class);
        Beta.canShowUpgradeActs.add(MainActivity.class);
        Beta.canShowUpgradeActs.add(AboutActivity.class);
        Beta.upgradeListener = UpgradeDialog.INSTANCE;

        CrashReport.UserStrategy strategy = new CrashReport.UserStrategy(getApplicationContext());
        strategy.setAppVersion(BuildConfig.VERSION_NAME);
        strategy.setAppChannel(getAppChannel());
        strategy.setAppReportDelay(10 * 1000);
        Bugly.init(getApplicationContext(), AppConfig.BUGLY_APPID, BuildConfig.DEBUG, strategy);
        CrashReport.setIsDevelopmentDevice(getApplicationContext(), BuildConfig.DEBUG);

    }
 
Example 6
Source File: App.java    From Yuan-WanAndroid with Apache License 2.0 5 votes vote down vote up
private void initBugly() {
    Context context = getApplicationContext();
    // 获取当前包名
    String packageName = context.getPackageName();
    // 获取当前进程名
    String processName = CommonUtils.getProcessName(android.os.Process.myPid());
    // 设置是否为上报进程
    CrashReport.UserStrategy strategy = new CrashReport.UserStrategy(context);
    strategy.setUploadProcess(processName == null || processName.equals(packageName));
    // 初始化Bugly
    CrashReport.initCrashReport(context, Constant.BUGLY_APP_ID, false, strategy);

}
 
Example 7
Source File: ReadhubApplicationLike.java    From JReadHub with GNU General Public License v3.0 5 votes vote down vote up
private void initBugly() {
    String packageName = getApplication().getPackageName();
    String processName = getProcessName(android.os.Process.myPid());
    CrashReport.UserStrategy strategy = new CrashReport.UserStrategy(getApplication());
    strategy.setUploadProcess(processName == null || processName.equals(packageName));

    Beta.storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
    Beta.autoCheckUpgrade = false;
    Beta.canShowUpgradeActs.add(MainActivity.class);
    String channel = WalleChannelReader.getChannel(getApplication());
    strategy.setAppChannel(channel);
    Bugly.init(getApplication(), "c16799f8bc", false, strategy);
}
 
Example 8
Source File: WanAndroidApp.java    From Awesome-WanAndroid with Apache License 2.0 5 votes vote down vote up
private void initBugly() {
    // 获取当前包名
    String packageName = getApplicationContext().getPackageName();
    // 获取当前进程名
    String processName = CommonUtils.getProcessName(android.os.Process.myPid());
    // 设置是否为上报进程
    CrashReport.UserStrategy strategy = new CrashReport.UserStrategy(getApplicationContext());
    strategy.setUploadProcess(processName == null || processName.equals(packageName));
    CrashReport.initCrashReport(getApplicationContext(), Constants.BUGLY_ID, false, strategy);
}
 
Example 9
Source File: App.java    From WanAndroid with Apache License 2.0 5 votes vote down vote up
private void initBugly() {
    if(BuildConfig.DEBUG) return;
    Context context = getApplicationContext();
    // 获取当前包名
    String packageName = context.getPackageName();
    // 获取当前进程名
    String processName = CommonUtil.getProcessName(context, android.os.Process.myPid());
    // 设置是否为上报进程
    CrashReport.UserStrategy strategy = new CrashReport.UserStrategy(context);
    strategy.setUploadProcess(processName == null || processName.equals(packageName));
    // 初始化Bugly
    CrashReport.initCrashReport(getApplicationContext(), Constant.BUGLY_ID, true);
}
 
Example 10
Source File: App.java    From cronet with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();

    CrashReport.UserStrategy strategy = new CrashReport.UserStrategy(getApplicationContext());
    strategy.setEnableANRCrashMonitor(true);
    strategy.setEnableNativeCrashMonitor(true);
    strategy.setBuglyLogUpload(true);
    CrashReport.initCrashReport(getApplicationContext(), "865e103a10", false, strategy);

}
 
Example 11
Source File: MyApplication.java    From NetEasyNews with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 初始化bugly
 */
private void initBugly() {
// 获取当前包名
    String packageName = mContext.getPackageName();
// 获取当前进程名
    String processName = getProcessName(android.os.Process.myPid());
// 设置是否为上报进程
    CrashReport.UserStrategy strategy = new CrashReport.UserStrategy(mContext);
    strategy.setUploadProcess(processName == null || processName.equals(packageName));
    CrashReport.initCrashReport(getApplicationContext(), "7a544c9222", false);
}
 
Example 12
Source File: EncyApplication.java    From Ency with Apache License 2.0 4 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();

    instance = this;

    appComponent = DaggerAppComponent
            .builder()
            .applicationModule(new ApplicationModule(this))
            .httpModule(new HttpModule())
            .build();

    SharePrefManager sharePrefManager = appComponent.getSharePrefManager();

    boolean nightMode = sharePrefManager.getNightMode();
    AppCompatDelegate.setDefaultNightMode(nightMode ? AppCompatDelegate.MODE_NIGHT_YES : AppCompatDelegate.MODE_NIGHT_NO);

    sharePrefManager.setLocalMode(AppCompatDelegate.getDefaultNightMode());
    sharePrefManager.setLocalProvincialTrafficPatterns(sharePrefManager.getProvincialTrafficPattern());

    // 初始化Bugly
    CrashReport.UserStrategy strategy = new CrashReport.UserStrategy(getApplicationContext());
    strategy.setAppVersion(String.valueOf(AppApplicationUtil.getVersionCode(getApplicationContext())));
    CrashReport.initCrashReport(getApplicationContext(), Constants.BUGLY_APP_ID, false); // debug版本设置为true,正式发布设置为false

    // 初始化Fragmentation
    Fragmentation.builder()
            // 设置 栈视图 模式为 悬浮球模式   SHAKE: 摇一摇唤出  默认NONE:隐藏, 仅在Debug环境生效
            .stackViewMode(Fragmentation.BUBBLE)
            // 开发环境:true时,遇到异常:"Can not perform this action after onSaveInstanceState!"时,抛出,并Crash;
            // 生产环境:false时,不抛出,不会Crash,会捕获,可以在handleException()里监听到
            .debug(false)
            // 实际场景建议.debug(BuildConfig.DEBUG)
            // 生产环境时,捕获上述异常(避免crash),会捕获
            // 建议在回调处上传下面异常到崩溃监控服务器
            .handleException(new ExceptionHandler() {
                @Override
                public void onException(Exception e) {
                    CrashReport.postCatchedException(e);  // bugly会将这个Exception上报
                }
            })
            .install();

    //搜集本地tbs内核信息并上报服务器,服务器返回结果决定使用哪个内核。
    QbSdk.PreInitCallback cb = new QbSdk.PreInitCallback() {
        @Override
        public void onViewInitFinished(boolean arg0) {
            //x5內核初始化完成的回调,为true表示x5内核加载成功,否则表示x5内核加载失败,会自动切换到系统内核。
            LogUtil.d("app", " onViewInitFinished is " + arg0);
        }

        @Override
        public void onCoreInitFinished() {

        }
    };
    //x5内核初始化接口
    QbSdk.initX5Environment(getApplicationContext(), cb);

    // 初始化LeakCanary
    if (LeakCanary.isInAnalyzerProcess(this)) {
        return;
    }
    LeakCanary.install(this);

    // 异常处理类
    if (!BuildConfig.DEBUG) {
        EncyCrashHandler.getInstance().setCrashHanler(this);
    }
}