使用带gcm的appcelerator时,设备上未收到推送通知

时间:2014-01-15 09:47:07

标签: android push-notification appcelerator appcelerator-mobile

我正在尝试使用谷歌云消息传递(gcm)通过appcelerator将推送通知服务实现到Android设备中,之前使用C2DM实现了这一点。

目前的情况是,我从设备到appcelerator帐户的订阅过程正在进行中。但是,从appcelerator帐户发送推送消息无法到达我的设备。

CCPushService.getInstance().getGCMSenderIdAsnyc(
    getApplicationContext(), Constants.PUSH_APP_KEY,
    new GCMSenderIdCallback() {
    public void receivedGCMSenderId(String senderId) {
        Log.i(TAG, "Got SenderId: " + senderId);
        CCPushService.getInstance().registerGCM(
                getApplicationContext(), senderId,
                Constants.PUSH_APP_KEY,
                new DeviceTokenCallback() {
                    public void receivedDeviceToken(
                            final String deviceToken) {
                        if (deviceToken == null
                                || deviceToken.length() == 0) {
                            Log.e(TAG,
                                    "GCM server refused request.Have you configured this app for ACS?");
                        } else {
                            // activityHandler.post(new
                            // Runnable() {
                            // public void run() {
                            mDeviceID = deviceToken;
                            try {
                                subscribePushNotifications(
                                        new ACSClient(
                                                Constants.PUSH_APP_KEY),
                                        mDeviceID, "Chat");
                            } catch (IOException e) {
                                e.printStackTrace();
                            } catch (JSONException e) {
                                // TODO Auto-generated catch
                                // block
                                e.printStackTrace();
                            } catch (ACSClientError e) {
                                // TODO Auto-generated catch
                                // block
                                e.printStackTrace();
                            }
                            // }
                            // });
                        }
                    }

public void subscribePushNotifications(ACSClient sdk, String deviceToken,
        String channel) throws IOException, ACSClientError, JSONException {

    String type = "android";
    Map<String, Object> data = new HashMap<String, Object>();
    data.put("device_token", deviceToken);
    data.put("channel", channel);
    data.put("type", type);


      CCResponse response = sdk.sendRequest(
      "push_notification/subscribe.json", CCRequestMethod.POST, data,
      false); CCMeta meta = response.getMeta(); if
      ("ok".equals(meta.getStatus()) && meta.getCode() == 200 &&
      "SubscribeNotification".equals(meta.getMethod())) { return;

     }
    SpiceManager spiceManager = new SpiceManager(JsonSpiceService.class);
    spiceManager.start(this);
    spiceManager.execute(new NotificationRequest(data),
            Constants.PUSH_CACHE_KEY, DurationInMillis.NEVER,
            new NotificationSubscriptionHandler());
     spiceManager.shouldStop();
}

为什么推送通知无法到达我的设备?

0 个答案:

没有答案