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

Launching the application from an url in the browser for BlackBerry?

I am developing one application where i will launch a url in the browser from which i will launch my application.

Suppose if i will click google.com, and press enter, it will launch my application. For that i tried with theHttpFilterRegistry API.

For reference i am using the HTTPFilterDemo application. But currently while launching the app, i am getting the NullPointerException.

I wrote the below code i the openFilter Method:

 

  public Connection openFilter( String name, int mode, boolean timeouts ) throws IOException
    {
        Logger.out("Protocol", "it is inside the openFilter method");
        _url = name.substring(2);
        _requestHeaders = new HttpHeaders();
        _responseHeaders = new HttpHeaders();
        _responseHeaders.setProperty(HttpProtocolConstants.HEADER_CONTENT_TYPE, "text/html");


        // Attempt to parse for the file name
        int slashIndex = name.indexOf('/', 2);
   if (_resultData == null) 
        {

final int modHandle = CodeModuleManager.getModuleHandle("AppLaunchBrowser");
                    Logger.out("Protocol", "here is the module handle:::" +modHandle);
                    final ApplicationDescriptor[] apDes = CodeModuleManager.getApplicationDescriptors(modHandle);
//                  final String[] arguments = new String[1];
                    final ApplicationDescriptor appDescriptor = new ApplicationDescriptor(apDes[0], new String[]{});
                    Logger.out("Protocol", "here is the app descriptor:::" +appDescriptor);
                    try {
                        final int appCode = ApplicationManager.getApplicationManager().runApplication(appDescriptor, true);
                        Logger.out("Protocol", "here is the app code:::" +appCode);
                    } catch (ApplicationManagerException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    } 
     }
        return this;
    }

 And in the application class i am creating alternative entry point and using like below:

 

public class AppLaunch extends UiApplication{
    public static void main(String args[])
    {
        Logger.out("AppLaunch", args+"length of the arguments::::" +args.length);
        if((args != null) && (args.length > 0) && (args[0].equals("background")))
        {
            Logger.out("AppLaunch", "in the alternate entry point");
//          Logger.out("AppLaunch", args+"length of the arguments::::" +args.length);
            HttpFilterRegistry.registerFilter("www.google.co.in", "com.innominds.ca", false);


        }
        else 
        {
            Logger.out("AppLaunch", "Inside the Applaunch");
            AppLaunch theApp = new AppLaunch();
            theApp.requestForeground();
            Logger.out("AppLaunch", "created the app launch object");
            theApp.enterEventDispatcher();
//          Logger.out("AppLaunch", "in the alternate entry point");
//          HttpFilterRegistry.registerFilter("www.google.co.in", "com.innominds.ca", false);
        }
    }

    public AppLaunch()
    {
        checkPermissions();
        showTestScreen();
    }

     /**
     * This method showcases the ability to check the current permissions for
     * the application. If the permissions are insufficient, the user will be
     * prompted to increase the level of permissions. You may want to restrict
     * permissions for the ApplicationPermissionsDemo.cod module beforehand in
     * order to demonstrate this sample effectively. This can be done in
     * Options/Advanced Options/Applications/(menu)Modules.Highlight
     * 'ApplicationPermissionsDemo' in the Modules list and select 'Edit
     * Permissions' from the menu.
     */
    private void checkPermissions()
    {

        ApplicationPermissionsManager apm = ApplicationPermissionsManager.getInstance();
        ApplicationPermissions original = apm.getApplicationPermissions();



        if(original.getPermission(ApplicationPermissions.PERMISSION_BROWSER_FILTER) == ApplicationPermissions.VALUE_ALLOW)
        {
            // All of the necessary permissions are currently available
            return;
        }


        ApplicationPermissions permRequest = new ApplicationPermissions();
        permRequest.addPermission(ApplicationPermissions.PERMISSION_BROWSER_FILTER);

        boolean acceptance = ApplicationPermissionsManager.getInstance().invokePermissionsRequest(permRequest);

        if(acceptance)
        {
            // User has accepted all of the permissions
            return;
        }
        else
        {

        }
    }


    /**
     * Shows the test screen to allow the user to exercise the application
     * permissions capabilities.
     */
    private void showTestScreen()
    {
        UiApplication.getUiApplication().pushScreen(new AppLaunchScreen());
    }
}

 can any one please help..sorry for posting almost the total code..Smiley Happy

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

Re: Launching the application from an url in the browser for BlackBerry?

Which statement is giving you the NPE?

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

That is the problem. I am not getting in which line NPE i...

That is the problem. I am not getting in which line NPE is coming. Because when i am trying to debug in the simulator, it is telling debugger not attached and not able to debug. As i am putting the logs, every log statement is printing in protocol.java class. it is returninng me the appcode which i am printing at last.                                                    

 

only in my application class logs are not printing. Dont know why?? But it is first going inside that class to register filter..

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

Re: That is the problem. I am not getting in which line NPE i...

Finally i was able to resolve this issue. Actually NPE is coming in some other callback methods because i was implementing the FilterBaseInterface.