簡體   English   中英

接收Google Cloud Messaging(GCM)通知以及日志詳細信息

[英]Google Cloud Messaging (GCM) Notification receiving with logs detail

我已經實現了gcm,可以將通知發送到我的應用程序,並且它確實可以完美運行。

我正在設備上收到通知,但問題是我正在獲取日志詳細信息,而可能是通知消息中而不是我要推送的人類可讀消息。

在此處輸入圖片說明

這是我用來發送通知的代碼:

$gcmApiKey = GOOGLE_API_KEY;
$pushApi = new PushAPI();
$sender = new \PHP_GCM\Sender($gcmApiKey);
$message = new \PHP_GCM\Message("1", $messsageVal);
try {
    $multicastResult = $sender->sendMulti($message, $deviceRegistrationId, 2);
    $results = $multicastResult->getResults();
    for ($i = 0; $i < count($deviceRegistrationId); $i++) {
        $regId = $deviceRegistrationId[$i];
        $result = $results[$i];
        $messageId = $result->getMessageId();
        if ($messageId != null) {
            $canonicalRegId = $result->getCanonicalRegistrationId();
            if ($canonicalRegId != null) {
                // same device has more than on registration id: update it
            }
        } else {
            $error = $result->getErrorCodeName();
            if ($error == \PHP_GCM\Constants::$ERROR_NOT_REGISTERED) {
                $pushApi->clearDeviceByDeviceId($regId);
            }
        }
    }
} catch (\InvalidArgumentException $e) {
    // $deviceRegistrationId was null
} catch (PHP_GCM\InvalidRequestException $e) {
    // server returned HTTP code other than 200 or 503
} catch (\Exception $e) {
    // message could not be sent
}

這是我正在使用的整個API的鏈接。 PHP_GCM

我嘗試用Google搜索它,但沒有得到任何糾正。

任何幫助將不勝感激。

您必須解析您的響應與解析Web服務響應相同,並且僅顯示味精。

嘗試使用以下方法從收到的意圖中獲取消息:

String msg=intent.getExtras().getString("msg");

然后顯示為:

 NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
                this).setSmallIcon(R.mipmap.app_icon)
                .setWhen(System.currentTimeMillis())
                .setAutoCancel(true)
                .setDefaults(Notification.DEFAULT_ALL)
                .setContentTitle(context.getString(R.string.app_name))
                .setStyle(new NotificationCompat.BigTextStyle().bigText(msg))
                .setContentText(msg);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM