Push notification 不合格样品-点燃火

Push notification 不合格样品-点燃火,push-notification,kindle-fire,Push Notification,Kindle Fire,由于KindleFire设备不支持GCM(以前是:C2DM),我现在正在搜索其他可用的最佳通知服务。Kindle Fire的最佳通知服务是什么?试试: Amazon设备消息(ADM)允许您从发送推送通知 云计算可以使运行应用程序的KindleFire设备启动 ADM是一种传输机制,经过优化,可对消息和消息进行排队 将它们交付到应用程序的目标实例。你用什么 这些信息由你决定。例如,在收到消息时, 您的应用可能会发布通知,显示自定义用户界面, 或同步数据 除了提供同类最佳的负载大小外,每个负载最大可

由于KindleFire设备不支持GCM(以前是:C2DM),我现在正在搜索其他可用的最佳通知服务。Kindle Fire的最佳通知服务是什么?

试试:

Amazon设备消息(ADM)允许您从发送推送通知 云计算可以使运行应用程序的KindleFire设备启动

ADM是一种传输机制,经过优化,可对消息和消息进行排队 将它们交付到应用程序的目标实例。你用什么 这些信息由你决定。例如,在收到消息时, 您的应用可能会发布通知,显示自定义用户界面, 或同步数据

除了提供同类最佳的负载大小外,每个负载最大可达6KB 消息,ADM是免费提供给开发者的

这里有一个:

请尝试以下方法:

Amazon设备消息(ADM)允许您从发送推送通知 云计算可以使运行应用程序的KindleFire设备启动

ADM是一种传输机制,经过优化,可对消息和消息进行排队 将它们交付到应用程序的目标实例。你用什么 这些信息由你决定。例如,在收到消息时, 您的应用可能会发布通知,显示自定义用户界面, 或同步数据

除了提供同类最佳的负载大小外,每个负载最大可达6KB 消息,ADM是免费提供给开发者的

这里有一个:

/**
 * Request that ADM deliver your message to a specific instance of your app.
 */
public void sendMessageToDevice(String registrationId, String accessToken) throws Exception
{                                        
    // JSON payload representation of the message.
    JSONObject payload = new JSONObject();

    // Define the key/value pairs for your message content and add them to the
    // message payload.
    JSONObject data = new JSONObject();
    data.put("firstKey", "firstValue");
    data.put("secondKey", "secondValue");
    payload.put("data", data);  

    // Add a consolidation key. If multiple messages are pending delivery for a particular
    // app instance with the same consolidation key, ADM will attempt to delivery the most
    // recently added item.
    payload.put("consolidationKey", "ADM_Enqueue_Sample");

    // Add an expires-after value to the message of 1 day. If the targeted app instance does not
    // come online within the expires-after window, the message will not be delivered.
    payload.put("expiresAfter", 86400);      

    // Convert the message from a JSON object to a string.
    String payloadString = payload.toString();

    // Establish the base URL, including the section to be replaced by the registration
    // ID for the desired app instance. Because we are using String.format to create
    // the URL, the %1$s characters specify the section to be replaced.
    String admUrlTemplate = "https://api.amazon.com/messaging/registrations/%1$s/messages";

    URL admUrl = new URL(String.format(admUrlTemplate,registrationId));

    // Generate the HTTPS connection for the POST request. You cannot make a connection
    // over HTTP.
    HttpsURLConnection conn = (HttpsURLConnection) admUrl.openConnection();
    conn.setRequestMethod("POST");
    conn.setDoOutput(true);

    // Set the content type and accept headers.
    conn.setRequestProperty("content-type", "application/json");
    conn.setRequestProperty("accept", "application/json");
    conn.setRequestProperty("X-Amzn-Type-Version ", "com.amazon.device.messaging.ADMMessage@1.0");
    conn.setRequestProperty("X-Amzn-Accept-Type", "com.amazon.device.messaging.ADMSendResult@1.0");

    // Add the authorization token as a header.
    conn.setRequestProperty("Authorization", "Bearer " + accessToken);

    // Obtain the output stream for the connection and write the message payload to it.
    OutputStream os = conn.getOutputStream();
    os.write(payloadString.getBytes(), 0, payloadString.getBytes().length);
    os.flush();
    conn.connect();

    // Obtain the response code from the connection.
    int responseCode = conn.getResponseCode();

    // Check if we received a failure response, and if so, get the reason for the failure.
    if( responseCode != 200)
    {  
        if( responseCode == 401 )
        {
            // If a 401 response code was received, the access token has expired. The token should be refreshed
            // and this request may be retried.
        }

        String errorContent = parseResponse(conn.getErrorStream());             
        throw new RuntimeException(String.format("ERROR: The enqueue request failed with a " +
                                         "%d response code, with the following message: %s",
                                         responseCode, errorContent));
    }
    else
    {
        // The request was successful. The response contains the canonical Registration ID for the specific instance of your
        // app, which may be different that the one used for the request.

        String responseContent = parseResponse(conn.getInputStream());          
        JSONObject parsedObject = new JSONObject(responseContent);

        String canonicalRegistrationId = parsedObject.getString("registrationID");

        // Check if the two Registration IDs are different.
        if(!canonicalRegistrationId.equals(registrationId))
        {              
            // At this point the data structure that stores the Registration ID values should be updated
            // with the correct Registration ID for this particular app instance.
        }
    }

}

private String parseResponse(InputStream in) throws Exception
{
    // Read from the input stream and convert into a String.
    InputStreamReader inputStream = new InputStreamReader(in);
    BufferedReader buff = new BufferedReader(inputStream);

    StringBuilder sb = new StringBuilder();
    String line = buff.readLine();
    while(line != null)
   {         
      sb.append(line);
      line = buff.readLine();
    }

    return sb.toString();
}