首页 文章

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

提问于
浏览
3

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

当我尝试跟踪曲棍球应用程序与 android platform (混合应用程序)集成时,它还说我要在 main activity 中添加一些代码,以便我可以找到这个

1 回答

  • 2

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

    将onCreate方法放入注册...

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

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

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

    有几个可用的操作但是你只需要使用“start”和“saveException”来控制错误发送到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();
    

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

    enter image description here

    enter image description here

相关问题