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

URL Scheme implementation using Alternate Entry Points

Hi,

 

In my application, i am implementing URL Schema. So when user will type a URL in the browser and get a response in the MIME type, i am getting the data. And then i am moving to the certain screen of my application.
 But other than this, if user will launch the app by clicking directly in the App Icon, it will launch the app.

 

So for this requirement, i have created two entry point:

 

  1.   One entry point is to run on the Background to register the app with BrowserContentProviderRegistry.
     And user will come from the URL, it will launch the app.
  2. Another is two launch the app normally by clicking app icon.

But now because of this two entry point, two app instance is created. And two different store also created. So if i am adding some data, in the normal launch(2 nd case), it is not displaying when user is coming from the Browser.

 

Here is my Application code:

 

if ((args != null) && (args.length > 0) && (args[0].equalsIgnoreCase("gui"))) 
				{
					Logger.out("ArcotOtpApp", "UI Part");
					theApp = new ArcotOtpApp();
					
					int directions = Display.DIRECTION_NORTH;
					UiEngineInstance engineInstance = Ui.getUiEngineInstance();
					if (engineInstance != null) 
					{
						engineInstance.setAcceptableDirections(directions);
					}
					
					theApp.enterEventDispatcher();
					
				}
			 	else if ((args != null) && (args.length > 0) && (args[0].equalsIgnoreCase("background"))) 
				{
					Logger.out("ArcotOtpApp", "background");
					BrowserContentProviderRegistry converterRegistry = BrowserContentProviderRegistry.getInstance();
				        
				        if (converterRegistry != null) 
				        {           
				            converterRegistry.register(new BrowserPlugin());            
				        }
} 
		} 
		catch (Exception e) 
		{
			Dialog.alert("Exception e= " + e.toString());
		} 
		
	}

 

 

And here is Browser Plugin Class:

 

ublic final class BrowserPlugin extends BrowserContentProvider implements BrowserPageContext 
{
    
	
		private static String[] ACCEPT = {"application/x-otp"};
		String username = null;
		String[] retAr = new String[0];
		Hashtable htUserDet = null;
		private BrowserContentBaseImpl browserContentBaseImpl = null;
		private ArcotOTPApplication mArcotOTPApp = null;
		private OTP mOtp = null;
//		ArcotOtpApp mTheApp = null;
//		private static String[] ACCEPT = {"application/x-vnd.rim.provdata"};
    
    /**
     * @see net.rim.device.api.browser.plugin.BrowserContentProvider#getAccept(net.rim.device.api.browser.field.RenderingOptions)
     */
    public String[] getAccept(RenderingOptions context) 
    {   
        return ACCEPT;
    }
    
    /**
     * @see net.rim.device.api.browser.plugin.BrowserContentProvider#getBrowserContent(net.rim.device.api.browser.plugin.BrowserContentProviderContext)
     */
    public BrowserContent getBrowserContent( BrowserContentProviderContext context) throws RenderingException 
    {
    	 Logger.out("BrowserPlugin", "here it is");
        if (context == null) 
        {
        	 Logger.out("BrowserPlugin", "context is null");
            throw new RenderingException("No Context is passed into Provider");
        }
        
        Logger.out("BrowserPlugin", "Inside the getBrowserContent");
        browserContentBaseImpl = new BrowserContentBaseImpl(context.getHttpConnection().getURL(), null, 
                                                                                                        context.getRenderingApplication(), context.getRenderingSession().getRenderingOptions(), context.getFlags());
        
        InputStream in = null;
        try 
        {
            in = context.getInputStream();
            if (in == null)
            {
                in = context.getInputConnection().openInputStream();
            }
            
            StringBuffer sb =  new StringBuffer();                        
            int ch;
            while (-1 != (ch = in.read()))
            {               
                sb.append((char)ch);                
            }      
            
            Logger.out("BrowserPlugin", "here is the url need to check: "+sb.toString());
            htUserDet = new Hashtable();
            StringTokenizer stknz = new StringTokenizer(sb.toString(), "&");
			while (stknz.hasMoreTokens()) {
				String token = stknz.nextToken();
				int pos = token.indexOf('=');
				String key = token.substring(0, pos);
				username = key;
				String val = token.substring(pos + 1);
				htUserDet.put(key, val);
				
				Logger.out("BrowserPlugin", "username is here :::::::::: "+key);
				
			}
           
			Logger.out("BrowserPlugin", "username is here :::::::::: "+htUserDet.get("n"));
			Logger.out("BrowserPlugin", "activation code is here :::::::::: "+htUserDet.get("c"));
//			
			
			ArcotOtpApp.getApplication().requestForeground();
            UiApplication.getUiApplication().invokeLater(new Runnable() {
				
				public void run() {
					
//				
//					UiApplication.getUiApplication().pushGlobalScreen(new AccountsListScreen(htUserDet.get("n").toString(), htUserDet.get("c").toString(), true), 1, UiEngine.GLOBAL_QUEUE);
					UiApplication.getUiApplication().pushScreen(new AccountsListScreen(htUserDet.get("n").toString(), htUserDet.get("c").toString(), true));
//					UiApplication.getUiApplication().pushScreen(new ProvisionForm(htUserDet.get("n").toString(), htUserDet.get("c").toString()));
				}
			});
           
        } 
        catch (IOException ioe) 
        {
            errorDialog(ioe.toString());
        }
        finally
        {
            if (in != null)
            {
                try
                {
                    in.close();
                }
                catch (IOException ioe)
                {
                        
                }
            }
        }
        
//        browserContentBaseImpl.setContent(vfm);
//        browserContentBaseImpl.setTitle(ACCEPT[0]);
        
        // Set browser page context, this will tell the browser how to display this field.
//        browserContentBaseImpl.setBrowserPageContext(this);
        
        return browserContentBaseImpl;
    }
    
    /**
     * @see net.rim.device.api.browser.plugin.BrowserContentProvider#getSupportedMimeTypes()
     */
    public String[] getSupportedMimeTypes() 
    {
    	 Logger.out("BrowserPlugin", "Mime type supported");
    	
        return ACCEPT;
    }    
    
    /**
     * @see net.rim.device.api.browser.plugin.BrowserPageContext#getPropertyWithBooleanValue(int, boolean)
     */
    public boolean getPropertyWithBooleanValue(int id, boolean defaultValue) 
    {
        return false;
    }    
    
    /**
     * @see net.rim.device.api.browser.plugin.BrowserPageContext#getPropertyWithIntValue(int, int)
     */
    public int getPropertyWithIntValue(int id, int defaultValue) 
    {
        if (id == BrowserPageContext.DISPLAY_STYLE) 
        {
            // Disable the scroll bar .
            return BrowserPageContext.STYLE_NO_VERTICAL_SCROLLBAR;
        }
        
        return 0;
    }    
    
    /**
     * @see net.rim.device.api.browser.plugin.BrowserPageContext#getPropertyWithObjectValue(int, java.lang.Object)
     */
    public Object getPropertyWithObjectValue(int id, Object defaultValue) 
    {
        return null;
    }
    
    /**
     * @see net.rim.device.api.browser.plugin.BrowserPageContext#getPropertyWithStringValue(int, java.lang.String)
     */
    public String getPropertyWithStringValue(int id, String defaultValue) 
    {
        return null;
    }
    
    /**
     * Presents a dialog to the user with a given message
     * @param message The text to display
     */
    public static void errorDialog(final String message)
    {
        UiApplication.getUiApplication().invokeLater(new Runnable()
        {
            public void run()
            {
                Dialog.alert(message);
            } 
        });
    }
    
    
}

 

 

Please help..

Developer
Posts: 16,997
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: URL Scheme implementation using Alternate Entry Points

static variables are not shared between instances, better use runtimestore if you want to share something.
for IPC you can use global events (for example from background service to UI)
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 271
Registered: ‎12-24-2010
My Device: BlackBerry 10
My Carrier: Airtel

Re: URL Scheme implementation using Alternate Entry Points

So you mean, when i am caliing from the background thread, below line:

 

ArcotOtpApp.getApplication().requestForeground();

 

it will not come to foreground??

 

And how can i use IPC?? Any documentation please share..

 

Thanks..

Developer
Posts: 16,997
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: URL Scheme implementation using Alternate Entry Points

use http://www.blackberry.com/developers/docs/7.1.0api/net/rim/device/api/system/ApplicationManager.html... to post an event, and http://www.blackberry.com/developers/docs/7.1.0api/net/rim/device/api/system/Application.html#addGlo... to receive it.

http://www.blackberry.com/developers/docs/7.1.0api/net/rim/device/api/system/RuntimeStore.html allows to share data between processes.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter