0

So my Android app uses GCM push notifications and implements a wakeful service to format the incoming notification. I am implementing corresponding avatar images for the notifications but the images are pulled from our server using REST.

My problem - if the app is not in the foreground (closed or disabled in standby mode) then I am unable to connect to retrieve the avatar resource. I have implemented my code from here: https://developer.android.com/google/gcm/client.html (under "Receive a message").

Question - how do I relaunch a closed app so that I can retrieve the avatar in order to add to the GCM notification?

Here is my snippet from when I create the notification:

    RestApi restApi = RestApi.getInstance(this);
    senderAvatarUrl = restApi.MyAppAvatarThumbnailUrl(id);
    bitmap = getBitmapFromURL(senderAvatarUrl);

    if (bitmap == null){
        bitmap = BitmapFactory.decodeResource(context.getResources(),R.drawable.placeholder_avatar);
    }

    bitmap = getCroppedBitmap(bitmap);

    mBuilder= new NotificationCompat.Builder(this).setAutoCancel(true)
                    .setSmallIcon(R.drawable.fourth_notification)
                    .setLargeIcon(bitmap)
                    .setContentTitle(nameShouldBe)
                    .setStyle(new NotificationCompat.BigTextStyle().bigText(msg))
                    .setLights(Color.GREEN, 100, 10000)
                    .setContentText(msg);

    mBuilder.build();

Thanks

ericlokness
  • 505
  • 1
  • 4
  • 12
  • 1
    The fact that GCM notifications are working even when device goes to deep sleep means wifi/data has already been established, so one of solutions I could think of might be using [**delay_while_idle**](http://developer.android.com/google/gcm/adv.html) flag to hold on to messages while device is idle or setting up the TTL( Time to live) feature. Or you can try something like applying wakelock on your connection to the server as well using a websocket [**Link**](https://github.com/schwiz/android-websocket-example). Hope it provided you with some ideas. – so_jin_ee Jan 21 '15 at 16:58
  • Thanks larryp you've gave me a good starting point. I appreciate the tips. – ericlokness Jan 22 '15 at 07:01
  • Thanks for the advice, but this is not the behavior that I want. I would like the notification to be sent while in sleep which works, but the avatar is not getting pulled if app is closed out or inactive for a while. – ericlokness Jan 30 '15 at 12:30

0 Answers0