整合Google Play服务成就和android通知
我正在使用Google Play服务为android游戏设置成就 目标: 在我的整合Google Play服务成就和android通知,android,notifications,google-play-services,achievements,Android,Notifications,Google Play Services,Achievements,我正在使用Google Play服务为android游戏设置成就 目标: 在我的onAchievmentUnlocked回调中,我想向设备发送一个通知,当用户触摸该通知时(无论他们在哪里),该设备将打开成就屏幕 什么有效: 通知正确发送,所有图标等均可见。但是,触摸notificatoin没有任何作用 “成就”活动确实有效,因为我有一个选项菜单项可以通过此代码在应用程序中调用它:activity.startActivityForResult(gameClient.getAchievements
onAchievmentUnlocked
回调中,我想向设备发送一个通知,当用户触摸该通知时(无论他们在哪里),该设备将打开成就屏幕
什么有效:
- 通知正确发送,所有图标等均可见。但是,触摸notificatoin没有任何作用
- “成就”活动确实有效,因为我有一个选项菜单项可以通过此代码在应用程序中调用它:
activity.startActivityForResult(gameClient.getAchievementsIntent(),Achievents\u ID)代码>
- 最新版本是14
- TargetSDKVersion为16
@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);
}
在此处使用此代码:
Games.Achievements.incrementImmediate(GoogleApiClient apiClient, String id, int numSteps)
.setResultCallback(new ResultCallback<Achievements.UpdateAchievementResult>() {
@Override
public void onResult(UpdateAchievementResult result) {
switch (result.getStatus().getStatusCode()) {
case GamesStatusCodes.STATUS_ACHIEVEMENT_UNLOCKED:
// the state of the achievement is STATE_UNLOCKED after an increment operation. Continuing to increment an already unlocked achievement will always return this status.
break;
case GamesStatusCodes.STATUS_ACHIEVEMENT_UNKNOWN:
// the achievement failed to update because could not find the achievement to update.
break;
case GamesStatusCodes.STATUS_ACHIEVEMENT_NOT_INCREMENTAL:
// achievement failed to increment since it is not an incremental achievement.
break;
case GamesStatusCodes.STATUS_ACHIEVEMENT_UNLOCK_FAILURE:
// the call to unlock achievement failed.
break;
}
}
});
Games.acgregations.incrementImmediate(GoogleApiClient-apiClient,String-id,int-numSteps)
.setResultCallback(新的ResultCallback