Android push not coming through at device

0 votes

Hi,

I tried to send push from php to android device, the push works if i use the appHQ console

but it doesn't work when i use PHP to send. The metering at appHQ shows that there's operation going through, but not at the push log.

i try to catch the exception, but nothing seems to be wrong.

i got the device token from the log when i registering the device, and the username as well

below is the php code i used

try {
    $pushNotificationService = App42API::buildPushNotificationService();
    $pushNotification = $pushNotificationService->sendPushMessageToDevice($userName, $deviceToken, $message);
    print_r("Message is :" . $pushNotification->getMessage());
    print_r("Expiry is :" . $pushNotification->getExpiry());
    print_r("UserName is :" . $pushNotification->getUserName());
    $jsonResponse = $pushNotification->toString();
} catch (App42Exception $exception) {
    $appErrorCode = $exception->getAppErrorCode();
    $httpErrorCode = $exception->getHttpErrorCode();
    if ($appErrorCode == 1709) {
        echo "User by the name '@userName' device token '@deviceToken' does not registered.";
    } else if ($appErrorCode == 1401) {
        // handle here for Client is not authorized  
    } else if ($appErrorCode == 1500) {
        // handle here for Internal Server Error  
    }
    $jsonText = $exception->getMessage();
    echo $jsonText;
}  

 

asked Apr 26, 2016 in Android by eskytech15 (20 points)

1 Answer

0 votes
 
Best answer

Hi,

If i understood your query correctly then it looks like there is an issue while sending messages to the users through PHP API. Could you please change the code in Util.php file and let me know if it resolves this issue. 

 
from:
 
public static function getUTCFormattedTimestamp() {
        date_default_timezone_set("UTC");
        return date("Y-m-d\TG:i:s") . substr((string) microtime(), 1, 4) . "Z";
    }
     public static function getUTCFormattedTimestamps($date) {
           date_default_timezone_set("UTC");
          return date("Y-m-d\TG:i:s", strtotime($date)) . substr((string) microtime(), 1, 4) . "Z";
}
 
to:
 
public static function getUTCFormattedTimestamp() {
        date_default_timezone_set("UTC");
        
        return date("Y-m-d\TH:i:s") . substr((string) microtime(), 1, 4) . "Z";
    }
     public static function getUTCFormattedTimestamps($date) {
           date_default_timezone_set("UTC");
          return date("Y-m-d\TH:i:s", strtotime($date)) . substr((string) microtime(), 1, 4) . "Z";
}
 

Regards,

Himanshu Sharma

answered Apr 26, 2016 by hs00105 (2,005 points)
selected Apr 27, 2016 by eskytech15
thank you, it does solved the question.
Great let me know if you need any other help from our side. We are happy to help you!!!

Regards,
Himanshu Sharma
Download Widgets
Welcome to ShepHertz Product line forum, where you can ask questions and receive answers from the community. You can also reach out to us on support@shephertz.com
...