FileConnection permission messages in j2me midp 2.0?

别说谁变了你拦得住时间么 提交于 2019-12-17 21:59:51

问题


I am using midp 2.0. Here, I am using FileConnection for read and write files on mobile memory. I am able to read and write files on mobiles successfully. But while I am trying to write file data on mobile, it asking message like below.

Application wants to read from the local file system

is it OK to read your files?

if I press yes, then it again shows

Application wants to write to the local file system

is it OK to update your files?

These message are continuously showing approximately 10 times.

Is there any way to prevent this repeating this more than one time?

I have included my fileWrite method for your reference also:

    public String fileWrite(String root)
{                
    FileConnection fc = null;
    String fName = "test.txt";
    DataOutputStream dos=null;
    try
    {
        fc = (FileConnection) Connector.open(root + fName, Connector.READ_WRITE);
        if(!fc.exists())
        {
            fc.create();
        }
        else
        {
            System.out.println("File Exists part");
            fc.delete();
            fc.create();
        }

        dos = fc.openDataOutputStream();
        dos.write("f".getBytes());
    }
    catch (Exception e)
    {
        e.printStackTrace();
    }
    finally
    {
        try
        {
            fc.close();
            dos.close();
        }
        catch (IOException e) { }
    }


return "Saved in "+root+fName;
    //return "NULL";
}//filewrite ends here*/

回答1:


This is not coding related issue. Basically this type of confirm alert asking for security purpose. Because you are using JSR-75.

In this purpose, You need to sign your application with atleast any 3rd party signature like one from Verisign or Thrawte and then go to the application settings - permissions - and set permission for "Access User Data" as "Ask only Once" or "Allow Always" (these settings might not be available for your unsiged app on the device.)

If you facing this Issue on the emulator, go to preferences and MIDP tab, set the application domain to Trusted and set permission as "Allow Always". For more info, see here...

Signing sites are,

Thawte

Verisign

Java Verified




回答2:


If you go to 3rd party trusted certificate means its minimum cost is RS.10000 per year. For deploying your application in client (final stage). It will worth.

But for testing, validating input, developing stage the cost is high. So check if your mobile has support for self signed certificate. If it supports self signed certificate, then process with self signed certificate.

But keep in mind self signed certificate is only for testing / development purpose. For delivering the project to client you should go to trusted party certificates.



来源:https://stackoverflow.com/questions/4644067/fileconnection-permission-messages-in-j2me-midp-2-0

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!