0

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

假设如果我单击google.com,然后按回车,它将启动我的应用程序。为此,我尝试使用HttpFilterRegistryAPI。

作为参考,我正在使用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());
    }
}
4

1 回答 1

0

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

于 2012-12-18T06:29:09.810 回答