如何将Hockey App与Hybrid移动应用程序集成

时间:2014-12-24 06:40:17

标签: ionic-framework hybrid-mobile-app hockeyapp

我正在尝试将我的混合移动应用(Inonic + Cordova)与hockey App集成 但问题是曲棍球应用程序支持原生应用程序(根据我的信息)。那么有没有可用的指南? 混合应用程序与曲棍球应用程序集成

当我尝试跟踪曲棍球应用程序与 android平台(混合应用程序)的集成时,它还说我要在主要活动中添加一些代码,以便我可以找到这个< / p>

1 个答案:

答案 0 :(得分:2)

主要活动在Android平台内... cordova / platforms / android / src /...

将onCreate方法放入Register ...

还有一些插件可以帮助完成此任务,例如https://github.com/peutetre/cordova-plugin-hockeyapp

考虑到很多崩溃JavaScript问题在本地世界都没有崩溃,使用其他方式来传递受控错误会很有帮助,例如saveException方法,尝试通过插件将其公开到javascript中,它会让它存储上下文信息错误:http://hockeyapp.net/help/sdk/android/3.0.1/net/hockeyapp/android/ExceptionHandler.html

我在前面提到的插件的一个分支中测试了仅适用于Android的解决方案https://github.com/m-alcu/cordova-plugin-hockeyapp

有几个可用的动作,但你只需要使用&#34; start&#34;和&#34; saveException&#34;将受控错误发送给hockeyapps。

hockeyapp.js:

var exec = require('cordova/exec');

var hockeyapp = {
    start:function(success, failure, token) {
        exec(success, failure, "HockeyApp", "start", [ token ]);
    },
    feedback:function(success, failure) {
        exec(success, failure, "HockeyApp", "feedback", []);
    },
    saveException:function(success, failure, description) {
        exec(success, failure, "HockeyApp", "saveException", [ description ]);
    }    
};

module.exports = hockeyapp;

hockeyapp.java:

package com.zengularity.cordova.hockeyapp;

import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaPlugin;
import org.json.JSONArray;
import android.widget.Toast;

import static net.hockeyapp.android.ExceptionHandler.saveException;
import net.hockeyapp.android.FeedbackManager;
import net.hockeyapp.android.CrashManager;
import net.hockeyapp.android.CrashManagerListener;

public class HockeyApp extends CordovaPlugin {

    public static boolean initialized = false;
    public static String token;
    public static String description;

    @Override
    public boolean execute(String action, JSONArray args, CallbackContext callbackContext) {
        if (action.equals("start")) {
            token = args.optString(0);
            CrashManager.register(cordova.getActivity(), token, null);
            initialized = true;
            callbackContext.success();
            return true;
        } else if(action.equals("feedback")) {
            token = args.optString(0);
            FeedbackManager.register(cordova.getActivity(), token, null);
            cordova.getActivity().runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    FeedbackManager.showFeedbackActivity(cordova.getActivity());
                }
            });
            callbackContext.success();
            return true;

        } else if(action.equals("saveException")) {
            description = args.optString(0);
            if(initialized) {

            Toast toast = Toast.makeText(cordova.getActivity(), "problem", Toast.LENGTH_SHORT);
            toast.show();

            cordova.getActivity().runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        Exception e = new Exception("Send problem");
                        saveException(e, new CrashManagerListener() {
                            public String getDescription() {
                                return description;
                            }
                        });
                    }
                });
                callbackContext.success();
                return true;
            } else {
                callbackContext.error("cordova hockeyapp plugin not initialized, call start() first");
                return false;                
            }  
        }
        else {
            return false;
        }
    }

}

在hellowold示例(index.js)中使用此插件的示例:

var app = {
    // Application Constructor
    initialize: function() {
        this.bindEvents();
    },
    // Bind Event Listeners
    //
    // Bind any events that are required on startup. Common events are:
    // 'load', 'deviceready', 'offline', and 'online'.
    bindEvents: function() {
        document.addEventListener('deviceready', this.onDeviceReady, false);
    },
    // deviceready Event Handler
    //
    // The scope of 'this' is the event. In order to call the 'receivedEvent'
    // function, we must explicitly call 'app.receivedEvent(...);'
    onDeviceReady: function() {
        app.receivedEvent('deviceready');
    },
    // Update DOM on a Received Event
    receivedEvent: function(id) {
        var parentElement = document.getElementById(id);
        var listeningElement = parentElement.querySelector('.listening');
        var receivedElement = parentElement.querySelector('.received');

        listeningElement.setAttribute('style', 'display:none;');
        receivedElement.setAttribute('style', 'display:block;');

        console.log('Received Event: ' + id);

        hockeyapp.start(
            function() { alert('hockeyapp initialised'); },
            function(msg) { alert(msg); },
            '< your APP ID >');

        hockeyapp.saveException(
            function() { alert('hockeyapp saveException'); },
            function(msg) { alert(msg); },
            'Something wrong has happened: bla bla bla...');    
    }
};

app.initialize();

Hockey将这些受控制的异常存储在应用程序的文件目录中,并要求在用户下次打开应用程序时将其发送:

enter image description here

enter image description here