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

此生再无相见时 提交于 2019-12-09 23:11:15

问题


I am building a game using google play game services on RealTimeMultiplayer concept, my questions is how to get access the all participants profile image to display. i am new to the google play game services, not found a solutions or any guidance on API. please guide me, can we access and how to access?


回答1:


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



来源:https://stackoverflow.com/questions/22679903/how-to-get-the-profile-image-of-participant-in-realtimemultiplayer-using-google

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