jaanus
jaanus

Reputation: 423

Is it possible to send push notification with message icon from the server side to android device via PyFCM

I want to send push notification to android application with icon from the server side. Is it possible or did i get it wrong? enter image description here If it's possible, then which image format are expected as an input for PyFCM method notify_single_device for parameter message_icon. Didn't get the answer from the source code in github.

It's just referred as an variable. Base64 doesn't go through.

Upvotes: 1

Views: 2901

Answers (1)

olucurious
olucurious

Reputation: 136

You can attach the url of the image to the message data payload in pyfcm:

data_message = {
    "icon_url" : "http//...."
}
push_service.notify_single_device(registration_id=registration_id, 
message_body=message_body, data_message=data_message)

And get the "icon_url" in your Android app and fetch it as Bitmap resource with:

public Bitmap getBitmapFromURL(String strURL) {
    try {
        URL url = new URL(strURL);
        HttpURLConnection connection = (HttpURLConnection) 
        url.openConnection();
        connection.setDoInput(true);
        connection.connect();
        InputStream input = connection.getInputStream();
        Bitmap myBitmap = BitmapFactory.decodeStream(input);
        return myBitmap;
    } catch (IOException e) {
        e.printStackTrace();
        return null;
    }
}

then use setLargeIcon (Bitmap icon) of NotificationCompat.Builder to set the image as the notification icon

Upvotes: 2

Related Questions