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: 271
Registered: ‎12-24-2010
My Device: BlackBerry 10
My Carrier: Airtel

Sending a download invitation using my application

Hi,

 

i am developing an app which is BBM integrated. in the screen, i have a send invitation button. When i am clicking that button, i want to send the invitation to one contact to download this app. For this i wrote the below code:

 

messagingService = context.getMessagingService();
messagingService.sendDownloadInvitation();

 But nothing is happening when i am clicking that button. Please help.

Developer
Posts: 271
Registered: ‎12-24-2010
My Device: BlackBerry 10
My Carrier: Airtel

Re: Sending a download invitation using my application

[ Edited ]

actually context is returning me the null value. BBMPlatformContext instance which i am creating in the UiApplication class, i am passing in the mainscreen or my screen. but it is coming null. In the below way i am registering my app with BBM.

appPlugin = new BBMAppPlugin();
    	
        invokeLater(new Runnable() 
        {
			public void run() 
			{
				try 
				{
					platformContext = BBMPlatformManager.register(appPlugin);
				} catch (Exception e) 
				{
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				
				if(platformContext == null)
				{
					PlatformListener contextListener = new PlatformListener();
					platformContext.setListener(contextListener);
				}
			}		
					
		});
        
        UiApplication.getUiApplication().pushScreen(new SendListScreen(platformContext));

 And this way i am trying to get that context, which i am using to invite a contact to download my app..

 

public SendListScreen(BBMPlatformContext context)
	{
		super(NO_HORIZONTAL_SCROLL);
		this.context = context;
		Logger.out("Grocery", "gfggfd" +context.toString());
		if(context != null)
		{
			messagingService = context.getMessagingService();
		}
}

public void fieldChanged(Field field, int context) 
	{
		if(field == btnSendInvite)
		{
			messagingService.sendDownloadInvitation();
		}
	}

 

My simulator is MDS 9800

Can any one pls explain what i should change in my code..  

Highlighted
Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Sending a download invitation using my application

Remember that this code is not executed in the order that it is written:

 

        invokeLater(new Runnable()
        {
   public void run()
   {
    try
    {
     platformContext = BBMPlatformManager.register(appPlugin);
    } catch (Exception e)
    {
     // TODO Auto-generated catch block
     e.printStackTrace();
    }
    
    if(platformContext == null)
    {
     PlatformListener contextListener = new PlatformListener();
     platformContext.setListener(contextListener);
    }
   }  
     
  });
       
        UiApplication.getUiApplication().pushScreen(new SendListScreen(platformContext));

 

If you debug this code, you will find that the platformContext is null when you execute this code:

UiApplication.getUiApplication().pushScreen(new SendListScreen(platformContext));

because the invokeLater has not run. 

 

There are a variety of ways of fixing this, but probably the easiest is to override the onUiEngineAttached() for your SendListScreen screen similarly to the following:

 

        protected void onUiEngineAttached(boolean attached) {
                super.onUiEngineAttached(attached);
                if ( attached ) {
                        // Start BBM here
                }
        }

 

I presume that you are aware you should connect your app to BBM only once.  This will do it each time you go into this screen.  Or are you disconnecting when you leave this screen?

 

One other thing.  This will NOT print a stackTrace

 

    } catch (Exception e)
    {
     // TODO Auto-generated catch block
     e.printStackTrace();
    }

 

Look at the RIM note on the Throwable Javadoc for an explanation.  You should put a better debugging output in this catch to make sure you are not missing exceptions.