How to get the Profile image of Participant in RealTimeMultiplayer using Google Play Game Services

拥有回忆 提交于 2019-12-04 19:46:22

Using the ImageManager class to load the ImagerUri is how I tackle it.

Below, I loop through each Participant in the currentRoom, and request their IconImageUri to be loaded by an ImageManager instance.

This can directly be used to inflate a view, but as I am using LibGDX, I save it as png for it to handle.

(You can see that I tell theGameInterface that it is null if their is no pic, either because there isn't one, or they are an "unknown" participant and therefore GPGS returns null)

        for (Participant p : mRoomCurrent.getParticipants()) {

            //makeToast("should be loading pic");
            ImageManager IM = ImageManager.create(this);
            IM.loadImage(new ImageManager.OnImageLoadedListener() {             

                @Override
                public void onImageLoaded(Uri arg0, Drawable drawable, boolean arg2) {
                    if(drawable == null) {
                        theGameInterface.picLoaded(participantID, null);
                    } else {
                        Bitmap bitmap = ((BitmapDrawable)drawable).getBitmap();
                        try {
                           FileOutputStream out = openFileOutput("pic" + participantID + ".png", Context.MODE_MULTI_PROCESS);
                           bitmap.compress(Bitmap.CompressFormat.PNG, 90, out);
                           out.flush();
                           out.close();
                        } catch (Exception e) {
                            e.printStackTrace();
                            //dLog(e.getStackTrace().toString());
                        }
                    }

            }
            }, p.getIconImageUri());

These were deduced from developer site

ImageManager and Participant

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!