从浏览器中的URL启动BlackBerry应用程序?

时间:2012-12-17 14:24:32

标签: blackberry

我正在开发一个应用程序,我将在浏览器中启动一个URL,我将从该应用程序启动我的应用程序。

假设我点击google.com,然后按输入,它将启动我的应用程序。为此我尝试使用HttpFilterRegistry API。

作为参考,我正在使用 HTTPFilterDemo 应用程序。但目前在启动应用程序时,我收到了NullPointerException

我在openFilter方法中编写了以下代码:

 
 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");
    Logger.out("Protocol", "here it is come ::::44444444");
    final int modHandle = CodeModuleManager.getModuleHandle("AppLaunchBrowser");
    Logger.out("Protocol", "here is the module handle:::" + modHandle);
    final ApplicationDescriptor[] apDes = CodeModuleManager.getApplicationDescriptors(modHandle);
    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;
}

在应用程序类中,我正在创建替代入口点并使用如下所示:

  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();
    }


    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
        {

        }
    }

    private void showTestScreen()
    {
        UiApplication.getUiApplication().pushScreen(new AppLaunchScreen());
    }
}

1 个答案:

答案 0 :(得分:0)

最后我能够解决这个问题。实际上NPE正在进入其他一些回调方法,因为我正在实现FilterBaseInterface。