2017-08-01 79 views
0

我想使用HockeyApp工具發送崩潰報告。所以我對這個崩潰報告很陌生。我已經瀏覽了these網站,但沒有得到我的想法。我嘗試按照他們所示的指示進行設置。僅使用HockeyApp工具發送崩潰報告(Android)

但無法在網站工具中收到崩潰報告。 所以,任何人都可以提供一個崩潰報告工具只使用曲棍球應用程序的例子。

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() 
} 
+0

你只是試圖測試崩潰功能是否工作? SDK配置爲捕獲和發送未處理的異常,目前處理的異常在HockeyApp平臺上不受支持。如果您只是檢查它是否按預期運行,則可以在按鈕點擊時拋出異常而不捕捉它。 –

+0

@Shawn Dyas是的,我正在測試崩潰功能是否正常工作..如果發生崩潰,應直接向開發人員[Hockeyapp](https://rink.hockeyapp.net/users/sign_in)帳戶報告。這是我的第一點。如何將日誌發送給Hockeyapp以處理期望和以上代碼的另一點是正確的。 – opalfire

回答

0

崩潰報告發送到應用程序啓動。

代碼段用於觸發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儀表盤,你只能看到在事件標籤事件名稱。要查找自定義事件的屬性,您必須鏈接到Application Insight。 HockeyApp在這方面有documentation,你可以參考。

+0

感謝凱文...我已經做了一些研究.. – opalfire

+0

在完成這些之前,我想知道我的構建是否正確@Kevin – opalfire

+0

@opalfire您的集成代碼是正確的。但是按鈕操作會觸發HockeySDK無法檢測到的處理異常。所以,如果你想測試崩潰報告功能,你必須刪除try-catch。 –