Android Open Source - droidBBpush Blackberry Push Service






From Project

Back to project page droidBBpush.

License

The source code is released under:

This is free and unencumbered software released into the public domain. Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a co...

If you think the Android project droidBBpush listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.arg3.examples.push;
/*from w  w w. j a  v  a2  s . com*/
import com.arg3.examples.push.enums.DeviceType;
import com.arg3.examples.push.model.Device;

import net.rim.pushsdk.commons.PushSDKException;
import net.rim.pushsdk.commons.PushSDKProperties;
import net.rim.pushsdk.commons.PushSDKPropertiesImpl;
import net.rim.pushsdk.commons.UnauthorizedException;
import net.rim.pushsdk.commons.content.Content;
import net.rim.pushsdk.commons.content.TextContent;
import net.rim.pushsdk.commons.http.HttpClientImpl;
import net.rim.pushsdk.pap.PapService;
import net.rim.pushsdk.pap.PapServiceImpl;
import net.rim.pushsdk.pap.StatusCode;
import net.rim.pushsdk.pap.control.DeliveryMethod;
import net.rim.pushsdk.pap.control.PPGType;
import net.rim.pushsdk.pap.control.PushMessageControl;
import net.rim.pushsdk.pap.control.QualityOfService;
import net.rim.pushsdk.pap.unmarshal.BadMessageException;
import net.rim.pushsdk.pap.unmarshal.PushResponse;

import org.json.simple.JSONObject;

import java.util.ArrayList;
import java.util.List;

import javax.inject.Inject;

/**
 * Created by ryan on 2014-09-25.
 */
public class BlackberryPushService {

    private static final String BB_TOKEN_PREFIX = "bb-";

    private static final String BB_APP_ID = "YourAppId";

    private static final String BB_APP_PASS = "YouAppPass";

    private static final String BB_BASE_URL = "http://yourpushurl";

    PapService service;

    @Inject
    BlackberryPushService() {

        service = new PapServiceImpl();
        PushSDKProperties props = new PushSDKPropertiesImpl();

        props.setPublicPpgAddress(props.getPublicPpgAddress().replace("${ppg.base.url}", BB_BASE_URL));

        HttpClientImpl client = new HttpClientImpl();
        client.setPushSDKProperties(props);

        service.setHttpClient(client);
        service.setPushSDKProperties(props);
    }

    public boolean sendMessage(List<String> addresses, String message) {

        PushMessageControl pushMessageControl = new PushMessageControl(PPGType.PUBLIC_PUSH);

        String id = String.valueOf(System.currentTimeMillis());

        pushMessageControl.setAddressList(addresses);
        pushMessageControl.setSourceReference(BB_APP_ID);

        pushMessageControl.setPushId(id);

        QualityOfService qos = new QualityOfService();
        qos.setDeliveryMethod(DeliveryMethod.CONFIRMED);

        pushMessageControl.setQualityOfService(qos);

        JSONObject data = new JSONObject();
        data.put("message", message);

        Content content = new TextContent(data.toString());

        try {
            PushResponse response = service.push(BB_APP_ID, BB_APP_PASS, BB_APP_ID, pushMessageControl, content);

            return (response.getCode() == StatusCode.ACCEPTED);
        } catch (BadMessageException | UnauthorizedException | PushSDKException e) {
            e.printStackTrace();

            return false;
        }
    }

    public boolean sendMessage(Device device, String message) {
        assert (device.getType() == DeviceType.Blackberry);

        ArrayList<String> addresses = new ArrayList<String>();

        // this should be the prefix you enabled on blackberry builds in the android.cfg
        addresses.add(device.getToken().replace(BB_TOKEN_PREFIX, ""));

        return sendMessage(addresses, message);
    }

}




Java Source Code List

com.arg3.droid.bbpush.ApplicationTest.java
com.arg3.examples.droidbb.MainActivity.java
com.arg3.examples.droidbb.MainApplication.java
com.arg3.examples.droidbb.MainModule.java
com.arg3.examples.droidbb.PushNotifier.java
com.arg3.examples.droidbb.PushRegistrar.java
com.arg3.examples.droidbb.PushService.java
com.arg3.examples.droidbb.annotations.ForApplication.java
com.arg3.examples.droidbb.gcm.GCMBroadcastReceiver.java
com.arg3.examples.droidbb.gcm.GCMBroadcastReceiver.java
com.arg3.examples.droidbb.gcm.GCMHandler.java
com.arg3.examples.droidbb.gcm.GCMHandler.java
com.arg3.examples.droidbb.gcm.GCMIntentService.java
com.arg3.examples.droidbb.gcm.GCMIntentService.java
com.arg3.examples.push.AndroidPushService.java
com.arg3.examples.push.ApplicationListener.java
com.arg3.examples.push.BaseServlet.java
com.arg3.examples.push.BlackberryPushService.java
com.arg3.examples.push.MainModule.java
com.arg3.examples.push.PushServlet.java
com.arg3.examples.push.SendServlet.java
com.arg3.examples.push.ViewServlet.java
com.arg3.examples.push.api.BaseAPIServlet.java
com.arg3.examples.push.api.RegisterDeviceServlet.java
com.arg3.examples.push.dao.DeviceDAO.java
com.arg3.examples.push.enums.DeviceType.java
com.arg3.examples.push.model.Device.java