欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

android教程之hockeyapp捕获异常示例

程序员文章站 2023-11-08 15:10:28
复制代码 代码如下:package com.example.testhockeyapp;import net.hockeyapp.android.crashmanager;...

复制代码 代码如下:

package com.example.testhockeyapp;
import net.hockeyapp.android.crashmanager;
import net.hockeyapp.android.crashmanagerlistener;
import net.hockeyapp.android.updatemanager;
import android.os.bundle;
import android.app.activity;
import android.view.menu;
import android.view.view;
import android.view.view.onclicklistener;
import android.widget.button;
import android.widget.toast;

public class mainactivity extends activity {

 private static final string app_id = "a7ab0fe5f11edc8afbfbc842ecc38ad7";

 string a = null;

 @override
 protected void oncreate(bundle savedinstancestate) {
  super.oncreate(savedinstancestate);
  setcontentview(r.layout.activity_main);
  button button = (button) findviewbyid(r.id.button1);
  button.setonclicklistener(new onclicklistener() {

   @override
   public void onclick(view v) {
   a.charat(23);

   }
  });
   checkforupdates();
 }

 @override
 public boolean oncreateoptionsmenu(menu menu) {
  // inflate the menu; this adds items to the action bar if it is present.
  getmenuinflater().inflate(r.menu.main, menu);
  return true;
 }

 @override
 protected void onresume() {
  // todo auto-generated method stub
  super.onresume();

  checkforcrashes();
 }
 private void checkforcrashes() {
  crashmanager.register(this, app_id, new crashmanagerlistener() {
   @override
   public void oncrashessent() {
    super.oncrashessent();
    runonuithread(new runnable() {

     @override
     public void run() {
      toast.maketext(getapplicationcontext(),
        "crash data was sent. thanks!",
        toast.length_long).show();
     }
    });
   }

   @override
   public void oncrashesnotsent() {
    super.oncrashesnotsent();
    runonuithread(new runnable() {

     @override
     public void run() {
      toast.maketext(
        getapplicationcontext(),
        "crash data failed to sent. please try again later.",
        toast.length_long).show();
     }
    });
   }
  });
 }
   private void checkforupdates() {
     // remove this for store builds!
     updatemanager.register(this, app_id);
   }
}