Question

I am facing problem in my J2me application.

"Allow application to use network to send or receive data?".....with buttons to select either "Yes" or "No".

If I select, "No", then nothing happens. (my application in walk and no network connection in this case I want to close application not in walk )

If I select, "Yes", then a new screen appears with,(application work fine )

Was it helpful?

Solution

If you click "No" in "Allow application to use network to send or receive data?" alert , it will throw SecurityException when trying to open the connection. Just catch the SecurityException. In catch block, call notifyDestroyed() to close the application.

StreamConnection s = null;

try {
s = (StreamConnection) Connector.open(searchContactUrl);
//your code
} catch (SecurityException se) {
   this.notifyDestroyed();
}

OTHER TIPS

Stuff like you ask about is covered in MIDP specification addendum: The Recommended Security Policy for GSM/UMTS Compliant Devices.

Above document is quite lengthy and complicated. For an easier to understand (though less precise) explanation, check this article: Understanding MIDP 2.0's Security Architecture:

... This article describes other MIDP 2.0 features that protect users and their devices from malicious software. You'll use the J2ME Wireless Toolkit 2.0... to learn how to work with MIDP 2.0's security architecture.

What Are Sensitive Operations?

The MIDP 2.0 specification defines an open-ended system of permissions. To make any type of network connection, a MIDlet must have an appropriate permission...

You are accessing an Restricted API in to your application. To use this application, your application must be singed with signing certificate like VesiSign or Thawte. Now coming to your problem is

  • when you press no :

    So when you are pressing no then it automatically assumes that your choice will also be NO, so it doesn't ask next time. When you access same api next time within single run, your application will not be able to access such apis in next occurrence.

  • when you press yes

    So when you are press yes your application proceeds further. But when you access restricted api again, it again warns you weather to access it or no. Some api requires one time user input(yes) while some requires each time you access them.

so to avoid this message only way is to sign your application.

In Java ME applications where access to network data security message will be displayed to the user. To remove this message should sign / certify the application from the manufacturers

Now the options are YES and NO were placed by you, the option NOT to close just use the code:

// Arrange for the MIDlet to be destroyed
this.notifyDestroyed(); // where this is an instance of the MIDlet

More information about the application certification:

http://www.developer.nokia.com/Distribute/Packaging_and_signing.xhtml (by Nokia)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top