Search code examples
javajava-menetwork-programmingmidp

Allow application to use network to send or receive data?


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 )


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