3

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

当我尝试将曲棍球应用程序与android 平台(混合应用程序)集成时,它还说我要在主要活动中添加一些代码,以便我可以在哪里找到它

4

1 回答 1

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

有几个可用的操作,但您只需要使用“start”和“saveException”将受控错误发送到 hockeyapps。

曲棍球应用程序.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;

曲棍球应用程序.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;
        }
    }

}

在 helloold 示例 (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 将这些受控异常存储在应用程序的文件目录中,并要求在用户下次打开应用程序时发送它:

在此处输入图像描述

在此处输入图像描述

于 2014-12-24T07:48:33.090 回答