Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
Posts: 275
Registered: ‎02-05-2010
My Device: Blackberry Z10
My Carrier: Bouygues Telecom

BBM shareContent

[ Edited ]

Hi,

I'm using the shareContent method of the MessagingService class in my app to share data between bbm users :

public abstract void shareContent(String content,
                                  BBMPlatformData cookie,
                                  String contactPickerTitle,
                                  BBMPlatformContactList ignoreList)
                                  
The BBM Developemnt Guide says :                                  
By default, shareContent() displays the contact picker
with all the BBM™ contacts that have your application installed. You can use the ignoreList argument to provide
a list of contacts that the user can choose to ignore.                                  

I can say that's not true. When invoked, my app is displaying the whole BBM contacts even if they don't have the app installed.
What am I doing wrong ?

Thanks for your help,
Laurent

Twitter : @LaurentKP
My apps
Developer
Posts: 78
Registered: ‎05-17-2012
My Device: 9900 - OS 7.0 Torch device
My Carrier: Reliance

Re: BBM shareContent

Hi

This is not to suggest but to get suggestion from you !!

If app is not installed those devices which have added in your contact list. How do you fetch all contact instead of fetching only those contacts who have your application.

Is it possible to get all the BBM contacts of my device irrespective of my app installed.

I have observed in 'ScreenMuncher' application and same was asked to RIM, but their simple response is ' It is not possible to fetch the contacts unless your app is installed'.

Here in your case, you are able to fetch all the contacts irrespective of the app installed.

Can you please suggest me if anything I can do to achieve this.

Thanks in Advance.
Developer
Posts: 275
Registered: ‎02-05-2010
My Device: Blackberry Z10
My Carrier: Bouygues Telecom

Re: BBM shareContent

I'm not fetching all bbm contacts in my app. It's not possible, you can only retrieve the contacts that have your app installed. But shareContent should prompt the user only a subset of the whole bbm contacts. But it does not. It acts like sendFile and show all contacts.
Twitter : @LaurentKP
My apps
Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: BBM shareContent

I was not aware that shareContent was restricted to contacts with your application, so your post was a surprise, but I see that is what the development guide says.  I suggest the guide is not correct.  If you want to only share content with people using your own app, use the the code supplied later in the same chapter to provide a ContactListProvider that only includes your own app. 

 

Let us hope someone from RIM can confirm that the documentation is not correct. 

Developer
Posts: 275
Registered: ‎02-05-2010
My Device: Blackberry Z10
My Carrier: Bouygues Telecom

Re: BBM shareContent

[ Edited ]

Thanks Peter, but I want to use the shareContent functionality and I can not provide the contact list to use but only the contact list to ignore.
Not sure someone at RIM is working on the java api, neither on the bbm java sdk... But let's hope !

Twitter : @LaurentKP
My apps
Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: BBM shareContent

You can use this form of shareContent:

 

public abstract void shareContent(String content,
                                  BBMPlatformData cookie,
                                  ContactListProvider clProvider,
                                  String contactPickerTitle)

 

and supply a ContactListProvider that supplies contacts who have your application. 

Developer
Posts: 275
Registered: ‎02-05-2010
My Device: Blackberry Z10
My Carrier: Bouygues Telecom

Re: BBM shareContent

Sorry but I'm not sure how I can build and provide a ContactListProvider !?!!

Why can't we just provide a BBMPlatformContactList like the other shareContent method ?

 

shareContent

public abstract void shareContent(String content,
                                  BBMPlatformData cookie,
                                  String contactPickerTitle,
                                  BBMPlatformContactList ignoreList)
Twitter : @LaurentKP
My apps
Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: BBM shareContent

Following is sample code to help you build a ContactListProvider.  Note that this code actually lets you choose a min and max application version for your app, so you can in fact give a ContactListProvider that only includes users with specific levels of your app.  I have used this on occasion.

 

Hopefully from the code you can figure out how to get a fill list regardless of version installed. 

 

Have you not already answered your question?  Is it not because that method will give a list of all users, not just users who have your app?  As you have found, the guide says one thing, the device does another.  I think we will find that the guide is wrong - the Javadocs do not say the list is restricted.  And you can do what you want using a ContactListProvider anyway.

 

Here is some sample code.  No warranty, I have edited it to remove company specific details so I may have inadvertently broken it.  I am sure you can figure it out.

 

import java.util.Enumeration;

import net.rim.blackberry.api.bbm.platform.*;
import net.rim.blackberry.api.bbm.platform.io.*;
import net.rim.blackberry.api.bbm.platform.profile.*;
import net.rim.blackberry.api.bbm.platform.service.*;

import net.rim.device.api.system.*;


/**
 * ContactListprovider Implementation so that we can request a Contact List
 * containing only users with our app or only users
 * with a minimum level of our app.
 */
public class MyContactListProvider implements ContactListProvider {

        private int [] minAppVersion = null;
        private int [] maxAppVersion = null;
        ContactListService contacts = null;

        public MyContactListProvider(ContactListService contacts, String minAppVersionString) {
                this(contacts, minAppVersionString, null);
        }

        public MyContactListProvider(ContactListService contacts, String minAppVersionString, String maxAppVersionString) {
                this.contacts = contacts;
                if ( minAppVersionString == null && maxAppVersionString == null ) {
                        this.minAppVersion = null; // Indicate we don't care
                        this.maxAppVersion = null;
                } else
                if ( minAppVersionString == null ) {
                        this.minAppVersion = new int [] { 0, 0, 0, 0 };
                } else {
                        this.minAppVersion = MyContactListProvider.getLevel(minAppVersionString);
                }
                if ( maxAppVersionString == null ) {
                        this.maxAppVersion = new int [] { 99, 99, 99, 99 };
                } else {
                        this.maxAppVersion = MyContactListProvider.getLevel(maxAppVersionString);
                }
        }

        public BBMPlatformContactList getContactsForGroup(int groupIndex) {
                if ( groupIndex == 0 ) {
                        if ( minAppVersion == null ) {
                                // Don't care about version - return full list
                                return contacts.getContactList();
                        } else {
                                // filter out those that do not have the required level of app
                                BBMPlatformContactList returnList = new BBMPlatformContactList();
                                BBMPlatformContactList ourList = contacts.getContactList();
                                Enumeration contactListEnum = ourList.getAll();
                                while (contactListEnum.hasMoreElements()) {
                                        BBMPlatformContact contact = (BBMPlatformContact) contactListEnum.nextElement();
                                        String contactAppLevelString = contact.getAppVersion();
                                        int [] contactAppLevel = MyContactListProvider.getLevel(contactAppLevelString);
                                        if ( MyContactListProvider.compareTo(minAppVersion, contactAppLevel) <= 0 &&
                                             MyContactListProvider.compareTo(maxAppVersion, contactAppLevel) >= 0 ) {
                                                returnList.add(contact);
                                        }
                                }
                                return returnList;
                        }
                }
                return new BBMPlatformContactList();
        }
        public int getDefaultGroupIndex() {
                return ContactListProvider.BBM_CONTACTS_WITH_APP;
        }
        public String[] getGroupNames() {
                return new String [] { "our app users" };
        }

        // Shared utility methods

        public static int [] getLevel(String appLevel) {
                // return array containing release levels
                int [] appLevelInt = new int [4];
                for ( int i = 0; i < appLevelInt.length; i++ ) {
                        appLevelInt[i] = 0;
                }
                if ( appLevel == null ) {
                        return appLevelInt;
                }
                try {
                        int firstIndexOfDot = appLevel.indexOf('.');
                        appLevelInt[0] = Integer.parseInt(appLevel.substring(0, firstIndexOfDot));
                        int secondIndexOfDot = appLevel.indexOf('.', firstIndexOfDot + 1);
                        appLevelInt[1] = Integer.parseInt(appLevel.substring( firstIndexOfDot + 1, secondIndexOfDot));
                        int thirdIndexOfDot = appLevel.indexOf('.', secondIndexOfDot + 1);
                        if ( thirdIndexOfDot == -1 ) {
                                appLevelInt[2] = Integer.parseInt(appLevel.substring( secondIndexOfDot + 1 ));
                        } else {
                                appLevelInt[2] = Integer.parseInt(appLevel.substring( secondIndexOfDot + 1, thirdIndexOfDot));
                                int fourthIndexOfDot = appLevel.indexOf('.', thirdIndexOfDot + 1);
                                if ( fourthIndexOfDot == -1 ) {
                                        appLevelInt[2] = Integer.parseInt(appLevel.substring( thirdIndexOfDot + 1));
                                } else {
                                        appLevelInt[2] = Integer.parseInt(appLevel.substring( thirdIndexOfDot + 1, fourthIndexOfDot));
                                }
                        }
                } catch (Exception e) {
                        System.out.println("Exception converting: " + appLevel + ", e: " + e.toString());
                }
                return appLevelInt;
        }

        public static int compareTo(int [] level1, int [] level2) {
                try {
                        for ( int i = 0; i < level1.length; i++ ) {
                                if ( level1[i] != level2[i] ) {
                                        return level1[i] - level2[i];
                                }
                        }
                        return 0;
                } catch (Exception e) {
                        System.out.println("Exception comparing levels: " + e.toString());
                }
                return 0;
        }

}

BlackBerry Development Advisor
Posts: 15,806
Registered: ‎07-09-2008
My Device: BlackBerry PRIV
My Carrier: Bell

Re: BBM shareContent


peter_strange wrote:

 

 

Let us hope someone from RIM can confirm that the documentation is not correct. 



Confirming that the documentation is not correct here.  I'll get that fixed for the next update.

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.