仅使用 HockeyApp 工具发送崩溃报告(Android)

Sending Crash Reports using ONLY HockeyApp tool(Android)

我想使用 HockeyApp 工具发送崩溃报告。所以我是这个崩溃报告的新手。我浏览了 these 网站,但我的 mind.I 没有按照他们显示的说明尝试设置。

但是无法在网站工具中接收崩溃报告。 那么谁能提供一个仅使用 Hockey App 的崩溃报告工具的示例。

test1.java

 public class test1 extends AppCompatActivity {

    private static final String TAG = "test1";
    private static final String APP_ID = "2aac21928b1242a19fa49ae4cf69a552";
    private Button errorBtn;
    private TextView textView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        errorBtn = (Button) findViewById(R.id.showSnackbarButton);
        setContentView(R.layout.activity_test1);
        textView=(TextView)findViewById(R.id.someText);

        errorBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {                
                File file = new File("E://file.txt");
                try {
                    FileReader fr = new FileReader(file);
                } catch (FileNotFoundException e) {
                    Log.d(TAG, "FilenotFound_Demo");
                    e.printStackTrace();
                }
            }
        });
        checkForUpdates();
    }

    @Override
    public void onResume() {
        super.onResume();
        // ... your own onResume implementation
        checkForCrashes();
    }

    @Override
    public void onPause() {
        super.onPause();
        unregisterManagers();
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        unregisterManagers();
    }


    private void checkForCrashes() {
        CrashManager.register(this, APP_ID, new CrashManagerListener() {
            public boolean shouldAutoUploadCrashes() {
                return true;
            }
        });

    }

    private void checkForUpdates() {
        // Remove this for store builds!
        UpdateManager.register(this,APP_ID);
    }

    private void unregisterManagers() {
        UpdateManager.unregister();
    }
}

我的构建模块:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    buildToolsVersion "26.0.0"
    defaultConfig {
        applicationId "com.example.river.tessting"
        minSdkVersion 19
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        manifestPlaceholders = [HOCKEYAPP_APP_ID: "2aac21928b1242a19fa49ae4cf69a552"]
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:26.+'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    compile 'net.hockeyapp.android:HockeySDK:4.1.5'
    testCompile 'junit:junit:4.12'
}
repositories {
    jcenter()
}

当您的应用程序崩溃时,系统会在应用程序下次启动时发送崩溃报告。

触发UnhandledException的代码片段:

        Button crashBtn = (Button) findViewById(R.id.crash_Btn);
        crashBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                throw new NullPointerException();
            }
        });

HockeyApp 不支持 Android 上的 handledException。但是您可以使用 UserMetrics 来跟踪它作为解决方法。

使用自定义事件跟踪 HandledException 信息:

    Button handledException = (Button) findViewById(R.id.handledException_Btn);
    handledException.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            try {
                throw new NullPointerException();
            }catch (Exception e){

                // add this wherever you want to track a custom event and attach properties or measurements to it
                HashMap<String, String> properties = new HashMap<>();
                properties.put("StackTrace", e.getStackTrace().toString());
                properties.put("Cause", e.getLocalizedMessage());

                HashMap<String, Double> measurements = new HashMap<>();
                measurements.put("YOUR_Measurement", 1.0);

                MetricsManager.trackEvent("YOUR_EVENT_NAME", properties, measurements);

            }

        }
    });

但是,在 HockeyApp 仪表板上,您只能在“事件”选项卡中看到事件名称。要查找自定义事件的属性,您必须 link 到 Application Insight。 HockeyApp 上有documentation 可以参考