Menu

update display picture for contact

Help
2009-03-12
2013-04-29
  • xuefeng wang

    xuefeng wang - 2009-03-12

    I am trying to get the display picture for the user following the example given by the MsnObjectMessenger example. I was able to get the display picture for the first run. However, if the contact update the display picture, how I would know about this.

    Is there a way to get a notification from the server when the user contact changes its display picture?

    Please help. Thanks

     
  • eaglesinblack

    eaglesinblack - 2012-01-06

    Yes it is possible. Sample Code for you :

    @Override
                public void contactStatusChanged(MsnMessenger messenger, MsnContact msnContact) {
                    System.out.println("Contact :" + msnContact.getEmail() + "Status Changed To:"
                            + msnContact.getStatus() + " Old Status was:" + msnContact.getOldStatus());
                    if (MsnObject.TYPE_DISPLAY_PICTURE == msnContact.getAvatar().getType()) {
                        System.out.println("Resim Degisti:" + msnContact.getAvatar().getMsnObj());
                        messenger.retrieveDisplayPicture(msnContact.getAvatar(),
                                                         new DisplayPictureListener() {
                                                             public void notifyMsnObjectRetrieval(
                                                                                                  MsnMessenger messenger,
                                                                                                  DisplayPictureRetrieveWorker worker,
                                                                                                  MsnObject msnObject,
                                                                                                  ResultStatus result,
                                                                                                  byte[] resultBytes,
                                                                                                  Object context) {
                                                                 // Log the result
                                                                 //                                                             log.info("Finished Avatar retrieval "
                                                                 //                                                                     + result);
                                                                 // Process next contact
                                                                 //retrieveNextContactAvatar(messenger);
           
                                                                 // Check for the value
                                                                 if (result == ResultStatus.GOOD) {
                                                                     // Create a new file to store the avatar
                                                                     File storeFile = new File("avatar"
                                                                             + System.currentTimeMillis()
                                                                             + ".png");
                                                                     System.out.println("File Path:"
                                                                             + storeFile.getAbsolutePath());
                                                                     try {
                                                                         FileOutputStream storeStream = new FileOutputStream(storeFile);
                                                                         storeStream.write(resultBytes);
                                                                         //goodAvatars.add(msnObject.getCreator());
                                                                         storeStream.close();
                                                                     } catch (FileNotFoundException e) {
                                                                         System.err.println("Critical error: Unable to find file we just created.");
                                                                     } catch (IOException e) {
                                                                         System.err.println("Critical error: Unable to write data to file system.");
                                                                     }
                                                                 } else {
                                                                     //unavailableAvatars.add(msnObject.getCreator());
                                                                 }
                                                             }
                                                         });
                    }
                    for (int j = 0; j < msnContact.getAvatar().getMsnObj().length; j++) {
                        System.out.println(msnContact.getAvatar().getMsnObj()[j]);
                    }
                    // TODO Auto-generated method stub
                    super.contactStatusChanged(messenger, msnContact);
                }
    
     
  • eaglesinblack

    eaglesinblack - 2012-01-06

    By the way is it possible to change profile picture. Is following code works for this issue ?

    DisplayPictureDuelManager displayPictureDuelManager = messenger.getDisplayPictureDuelManager();
    displayPictureDuelManager.setDisplayPicutre(msnObject);

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.