I am using Google Play services to set up achievements for an android game.
Goal:
In my onAchievmentUnlocked
callback I want to send a notification to the device that opens the achievement screen when the user touches the notification (from wherever they are).
What works:
- The notification gets sent properly and all the icons etc. are visible. Touching the notificatoin does nothing though.
- The achievement activity does work, since I have an Option Menu item to call it up in the app via this code:
activity.startActivityForResult(gameClient.getAchievementsIntent(), ACHIEVEMENTS_ID);
What's not working: Touching the notification has no apparent effect.
Notes:
- MinSDKVersion is 14
- TargetSDKVersion is 16
Here's the code I have at present:
@Override
public void onAchievementUnlocked(final String id) {
final Achievement ac = mAchievementManager.getUnlockedAchievements().get(id);
assert(ac!=null);
Uri uri = ac.getUnlockedImageUri();
final Context ctx = this;
ImageManager.OnImageLoadedListener listener = new ImageManager.OnImageLoadedListener() {
@Override
public void onImageLoaded(Uri uri, Drawable drawable) {
Bitmap bitmap = ((BitmapDrawable)drawable).getBitmap();
Notification.Builder builder = new Notification.Builder(ctx)
.setContentTitle(APP_TITLE_STRING)
.setContentText(ac.getName() + " achievement unlocked")
.setLargeIcon(bitmap)
.setSmallIcon(R.drawable.ic_trophy);
Intent intent = mLoginFragment.getGamesClient().getAchievementsIntent();
PendingIntent pIntent = PendingIntent.getActivity(ctx, AchievementManager.REQUEST_ACHIEVEMENTS, intent, Intent.FLAG_ACTIVITY_NEW_TASK);
builder.setContentIntent(pIntent);
Notification note;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) note = builder.build();
else note = builder.getNotification();
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(1, note);
}
};
mImageManager.loadImage(listener,uri,R.drawable.ic_trophy);
}