2012-12-17 82 views
0

我正在開發一個應用程序,我將在其中啓動我的應用程序的瀏覽器中啓動一個URL。從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()); 
    } 
} 
+0

你可以發佈NPE被引發的行嗎? –

+0

我沒有得到它扔的地方。因爲evry登錄代碼正在執行,除非在AppLaunch類中,我正在創建備用入口點.. –

+0

我想調試它..但它告訴調試文件丟失..所以我無法找出NPE的確切位置.. –

回答

0

最後我能解決這個問題。實際上NPE正在進入一些其他的回調方法,因爲我實現了FilterBaseInterface。

相關問題