12-17-2012 11:56 AM
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("AppLaunchBrowse r");
Logger.out("Protocol", "here is the module handle:::" +modHandle);
final ApplicationDescriptor[] apDes = CodeModuleManager.getApplicationDescriptors(modHan dle);
// 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().runAppl ication(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.P ERMISSION_BROWSER_FILTER) == ApplicationPermissions.VALUE_ALLOW)
{
// All of the necessary permissions are currently available
return;
}
ApplicationPermissions permRequest = new ApplicationPermissions();
permRequest.addPermission(ApplicationPermissions.P ERMISSION_BROWSER_FILTER);
boolean acceptance = ApplicationPermissionsManager.getInstance().invoke PermissionsRequest(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..![]()
Solved! Go to Solution.
12-17-2012 06:40 PM
Which statement is giving you the NPE?
12-17-2012 10:08 PM
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..
12-18-2012 02:58 AM
Finally i was able to resolve this issue. Actually NPE is coming in some other callback methods because i was implementing the FilterBaseInterface.