FileConnection Exception on Myphone Device - not authorized to access the restricted API

451 Views Asked by At

I developed application in J2ME in which I have to make a file connection, but when I run this application it gives an exception:

Application not authorized to access the restricted API

I signed the build using the signing server and it works fine in other device except this device. Below is my code for the same.

Below is my code for file connection. It first constructs the filepath

 String dir = "file://" + Util.get_root_dirFrom() + "m/demo.res"; // Filepath for the application
 Log.p("Inside the loadString method......dir");
 FileConnection fc = null;
 InputStream fis = null;
 try {
   fc = (FileConnection) Connector.open(dir, Connector.READ);// Make a file connection
   fis = fc.openInputStream();
 }catch(Exception ex){
   Log.p("Exception...."+ex.getMessage());
 }

Util.get_root_dirFrom() methods return the dir for memory card in this device.

How to resolve this issue?

2

There are 2 best solutions below

1
On

I don't think it's the code's problem.

Cell phones has this security against some J2ME functions.
You probably just have to set the Application's permission settings so that it can be able to read/write on the file system.

Exactly how you have to do that depends from phone to phone, but you'll probably find it fast.

1
On

i think SmRndGuy answer is correct.Better you choose another folder for file io operations