Reputation: 1129
In my j2me application, I receive above exception(java.lang.securityException not allowed to open connection
). The flow of my function is like first I open socket for Receiving message in the constructor and then for sending SMS I open ports in the method body, on my phone MIDlet asks for permission to send SMS, if I press NO it shows security exception that SMS sending not denied, that's OK. But when being in the same MIDlet and performing this action second time it gives exception at the time of opening receiving port in the constructor as java.lang.securityException not allowed to open connection
. At this time I yet not seen any permission asking for sending SMS for second time. My code for Constructor and SMS Sending is below:
//Constructor
public ServerContactRetriever(MainMidlet parent, Language lang) {
try {
this.language = lang;
this.parent = parent;
recvCon = (MessageConnection) Connector.open(RECV_URL); //open receiving port
recvCon.setMessageListener(this);
} catch (Exception ex) {
parent.dispErrorMessage(language.access_denied_disp);
parent.alertShow(language.access_denied_alert);
}
}
//METHOD
//Request restore contacts from server
private void sendRestoreRequest() {
try {
MessageConnection msgCon = (MessageConnection) Connector.open(SEND_URL);
TextMessage msg = (TextMessage) msgCon.newMessage(MessageConnection.TEXT_MESSAGE);
msg.setAddress(SEND_URL);
msg.setPayloadText("set payload here");
msgCon.send(msg);
msgCon.close();
} catch (Exception ex) {
try {
parent.alertShow(language.sms_error_alert);
parent.dispErrorMessage(language.sms_error_disp);
recvCon.close();
} catch (Exception ex1) {
}
}
}
I am using WTK with MIDP 2.0.
Checking over Nokia Devices.
First I wonder there could be issue of closing MessageConnection
port, but I tried that too and it shows the same error. Whereas about SMS send and I select NO, it works fine if I just try to send SMS and select NO as many times as I want and it still stays on the midlet without any exception. Thanks
Upvotes: 1
Views: 1388
Reputation: 467
There is no issue with closing MessageConnection. In some of the s40 and Symbian phones(like X2-02), the permission will be asked only once for one entire session. If you choose 'Yes', it wont ask you again while connecting second time. It will directly connect. Similarly, if you select 'No', while connecting first time, no connections will be allowed(securityException will be thrown) on every attempt to connect.
On some Nokia phones, you might see this option,
Select the application->Options->Application Access->Communication-> 1. Ask Every time 2. Ask first time 3. Always allowed 4. Not allowed.
You can select the one that is appropriate to you.
If you don't want your application to seek permissions at all, you need to have your app signed by Manufacturer.
Upvotes: 0