×

Discussion Board

Results 1 to 12 of 12
  1. #1
    Regular Contributor
    Join Date
    Jan 2009
    Posts
    103

    How shall i display an message "Required Application permission not granted" ??

    when i am accessing the data of phone or memory card like displaying the list of folders exsisted (while file browsing ) it prompts me for permission "To allow application to edit and add new data" with yes and no optoions

    if user selects yes - then application will read the data and there will be no exception
    if user selects No- then it display "Application Error" Instead of displaying this i want to display some message so.
    How shall i display an message "Required Application permission not granted" when user selects no during permision promts

    i have written application in J2ME

  2. #2
    Nokia Developer Champion
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    3,087

    Re: How shall i display an message "Required Application permission not granted" ??

    You need to put your JSR-75 code of file access in a Try Catch loop and capture all possible exceptions.
    In case of Security Exception you will require to display this prompt to the user.

    thanks,
    ~Amitabh

  3. #3
    Regular Contributor
    Join Date
    Jan 2009
    Posts
    103

    Re: How shall i display an message "Required Application permission not granted" ??

    Quote Originally Posted by im2amit View Post
    You need to put your JSR-75 code of file access in a Try Catch loop and capture all possible exceptions.
    In case of Security Exception you will require to display this prompt to the user.

    thanks,
    ~Amitabh
    I HAVE INSERTED ALL THE CODE IN TRY CATCH BUT ITS SHOWING NULL POINTER EXCEPTION

  4. #4
    Nokia Developer Champion
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    3,087

    Re: How shall i display an message "Required Application permission not granted" ??

    Try to put an addtional try/catch block, where you are trying to access FileSystem for the first time, (just for that Line) and print the exception that you capture in SOP, you should get a Security excepetion....
    if you still don't get it... please cut/paste the relevent code block for review which is throwing null pointer instead of Security exception.

    thanks,
    ~Amitabh

  5. #5
    Regular Contributor
    Join Date
    Jan 2009
    Posts
    103

    Re: How shall i display an message "Required Application permission not granted" ??

    Quote Originally Posted by im2amit View Post
    Try to put an addtional try/catch block, where you are trying to access FileSystem for the first time, (just for that Line) and print the exception that you capture in SOP, you should get a Security excepetion....
    if you still don't get it... please cut/paste the relevent code block for review which is throwing null pointer instead of Security exception.

    thanks,
    ~Amitabh
    I WILL TRY IT OUT BY PUTTING sop IF I STILL GET EXCEPTION THEN I WILL CUT AND PASTE THE CODE HERE

  6. #6
    Nokia Developer Champion
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    3,087

    Re: How shall i display an message "Required Application permission not granted" ??

    Sure, test the entire thing using SOP on emulator, if works then try on device... if fails on device use On-Device-Debuging options to see SOP's and fix... if it fails even then... then I am here online to review your code.


    thanks,
    ~Amitabh
    PS: Please don't use ALL CAPS in your post... it doesn't look nice.

  7. #7
    Regular Contributor
    Join Date
    Jan 2009
    Posts
    103

    Re: How shall i display an message "Required Application permission not granted" ??

    Quote Originally Posted by im2amit View Post
    Sure, test the entire thing using SOP on emulator, if works then try on device... if fails on device use On-Device-Debuging options to see SOP's and fix... if it fails even then... then I am here online to review your code.


    thanks,
    ~Amitabh
    PS: Please don't use ALL CAPS in your post... it doesn't look nice.
    i am pasting the code i think here sorewhere null pointer exception might be occuring

    Code:
     public void Tofile(String path, String content) {
            javax.microedition.io.Connection c1 = null;
            java.io.OutputStream os1 = null;
    
            String s2 = content;
            byte[] b2;
    
    
            b2 = s2.getBytes();
    
            try {
    
                c1 = javax.microedition.io.Connector.open(path, javax.microedition.io.Connector.READ_WRITE);
                javax.microedition.io.file.FileConnection fc = (javax.microedition.io.file.FileConnection) c1;
    
    
                if (!fc.exists()) {
                    fc.create();
    
                } else {
                    fc.truncate(0);
                }
    
                os1 = fc.openOutputStream(1);
    
                os1.write(b2);
                
                os1.flush();
    
    
            } catch (Exception e) {
                
            } finally {
                try {
                    if (os1 != null) {
                        os1.close();
                    }
    
                    if (c1 != null) {
                        c1.close();
                    }
                } catch (Exception ex) {
                    
                }
            }
        }
    this code to write into file even after writing to file null pointer exception is displaying but content are written into file sucessfully after writing its displaying application error i.e Null pointer exception


    Regards
    Divya
    Last edited by J2meDeveloper; 2009-08-29 at 09:08.

  8. #8
    Regular Contributor
    Join Date
    Jan 2009
    Posts
    103

    Re: How shall i display an message "Required Application permission not granted" ??

    Code:
    import java.util.*;
    import java.io.*;
    import javax.microedition.io.*;
    import javax.microedition.io.file.*;
    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.*;
    
    public class FileMidlet extends MIDlet implements CommandListener 
    {
      private String currDirName;
    
      private Command view = new Command("View", Command.ITEM, 1);
      private Command back = new Command("Back", Command.BACK, 2);
      private Command exit = new Command("Exit", Command.EXIT, 3);
      
      private final static String UP_DIRECTORY = "..";
      private final static String MEGA_ROOT = "/";
      private final static String SEP_STR = "/";
      private final static char   SEP = '/';
    
      public FileMidlet() 
      {
        currDirName = MEGA_ROOT;
      }
    
      public void startApp() 
      {
    try{
        boolean isAPIAvailable = false;
        if (System.getProperty(
          "microedition.io.file.FileConnection.version") != null)
        {
          isAPIAvailable = true;
          try 
          {
            showCurrDir();
          } 
          catch (SecurityException e) 
          {} 
          catch (Exception e) {}
          }
        else
        {
          StringBuffer splashText = new StringBuffer(
            getAppProperty("MIDlet-Name")).append("\n").append(
            getAppProperty("MIDlet-Vendor")).
            append(isAPIAvailable?"":"\nFileConnection API not available");
          Alert splashScreen = new Alert(null,splashText.toString(),
            null,AlertType.INFO);
          splashScreen.setTimeout(3000);
          Display.getDisplay(this).setCurrent(splashScreen);
        }
       
    }
     catch(SecurityException e){
                System.out.println("Security exception");
                    CurrentDirEnum=null ;
            } 
      }
    
      public void pauseApp() {}
    
      public void destroyApp(boolean cond) 
      {
        notifyDestroyed();
      }
    
      public void commandAction(Command c, Displayable d) 
      {
        if (c == view) 
        {try{
          List curr = (List)d;
          final String currFile = curr.getString(curr.getSelectedIndex());
          new Thread(new Runnable() 
          {
            public void run() 
            {
              if (currFile.endsWith(SEP_STR) || 
                currFile.equals(UP_DIRECTORY)) 
              {
                traverseDirectory(currFile);
              } else 
              {
                showFile(currFile);
              }
            }
          }).start();
        }
     catch(SecurityException e){
                System.out.println("Security exception");
                    CurrentDirEnum=null ;
            }
    }
        else if (c == back) 
        {
          showCurrDir();
        } 
        else if (c == exit) 
        {
          destroyApp(false);
        }
      }
    
      void showCurrDir() 
      {
        Enumeration e;
        FileConnection currDir = null;
        List browser;
        try 
        {
          if (MEGA_ROOT.equals(currDirName)) 
          {
            e = FileSystemRegistry.listRoots();
            browser = new List(currDirName, List.IMPLICIT);
          } 
          else 
          {
            currDir = (FileConnection)Connector.open(
              "file://localhost/" + currDirName);
            e = currDir.list();
            browser = new List(currDirName, List.IMPLICIT);
            browser.append(UP_DIRECTORY);
          }
          while (e.hasMoreElements()) 
          {
            String fileName = (String)e.nextElement();
            if (fileName.charAt(fileName.length()-1) == SEP) 
            {
              browser.append(fileName);
            } 
            else 
            {
              browser.append(fileName);
            }
          }
          browser.setSelectCommand(view);
          browser.addCommand(exit);
          browser.setCommandListener(this);
          if (currDir != null) 
          {
            currDir.close();
          }
          Display.getDisplay(this).setCurrent(browser);
        } 
     catch(SecurityException e){
                System.out.println("Security exception");
                    CurrentDirEnum=null ;
            }
        catch (IOException ioe) 
        {}
      }
      
      void traverseDirectory(String fileName) 
      {
    try{
        if (currDirName.equals(MEGA_ROOT)) 
        {
          if (fileName.equals(UP_DIRECTORY)) 
          {
            // can not go up from MEGA_ROOT
            return;
          }
          currDirName = fileName;
        } 
        else if (fileName.equals(UP_DIRECTORY)) 
        {
          // Go up one directory
          // TODO use setFileConnection when implemented
          int i = currDirName.lastIndexOf(SEP, currDirName.length()-2);
          if (i != -1) 
          {
            currDirName = currDirName.substring(0, i+1);
          } 
          else 
          {
            currDirName = MEGA_ROOT;
          }
        } 
        else 
        {
          currDirName = currDirName + fileName;
        }
        showCurrDir();
      }
     catch(SecurityException e){
                System.out.println("Security exception");
                    CurrentDirEnum=null ;
            }
    }
    
      
      void showFile(String fileName) 
      {
        try 
        {
          FileConnection fc = (FileConnection)
          Connector.open("file://localhost/" + currDirName + fileName);
          if (!fc.exists()) 
          {
            throw new IOException("File does not exists");
          }
          InputStream fis = fc.openInputStream();
          byte[] b = new byte[1024];
          int length = fis.read(b, 0, 1024);
          fis.close();
          fc.close();
    
          TextBox tb = new TextBox("View File: " + fileName, null, 1024,
              TextField.ANY | TextField.UNEDITABLE);
      
          tb.addCommand(back);
          tb.addCommand(exit);
          tb.setCommandListener(this);
    
          if (length > 0) 
          {
            tb.setString(new String(b, 0, length));
          }
          Display.getDisplay(this).setCurrent(tb);
        }
     catch(SecurityException e){
                System.out.println("Security exception");
                    CurrentDirEnum=null ;
            }
        catch (Exception e) {}
      }
    }
    am using above code for file browsing purpose it works fine but whenpermission is not allowed it shows null pointer exception

    regards
    divya
    Last edited by J2meDeveloper; 2009-08-29 at 09:05.

  9. #9
    Nokia Developer Champion
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    3,087

    Re: How shall i display an message "Required Application permission not granted" ??

    Your code --
    try {
    c1 = javax.microedition.io.Connector.open(path, javax.microedition.io.Connector.READ_WRITE);
    javax.microedition.io.file.FileConnection fc = (javax.microedition.io.file.FileConnection) c1;
    if (!fc.exists()) {
    fc.create();
    } else {
    fc.truncate(0);
    }
    os1 = fc.openOutputStream(1);
    os1.write(b2);
    os1.flush();
    } catch (Exception e) {
    Lets try changing it to as under:
    try {
    //c1 = javax.microedition.io.Connector.open(path, javax.microedition.io.Connector.READ_WRITE);
    //javax.microedition.io.file.FileConnection fc = (javax.microedition.io.file.FileConnection) c1;

    FileConnection fc = (FileConnection)Connector.open(path); // this can through IOException
    // If no exception is thrown, then the URI is valid, but the file may or may not exist.


    if (!fc.exists()) {
    fc.create();
    } else {
    fc.truncate(0);
    }
    try{
    os1 = fc.openOutputStream(1); // java.lang.SecurityException can be thrown from here.
    }catch( Exception ee ) { System.out.println("Exception (may be SecurityException): "+ ee);}
    if(null!=os1){
    os1.write(b2);
    os1.flush();
    }
    } catch (Exception e) { System.out.println("Exception: "+ e);}
    The security model is also applied during use of the returned FileConnection, specifically when the methods openInputStream(), openDataInputStream(), openOutputStream(), and openDataOutputStream() are invoked. These methods have implied request for access rights (i.e. input stream access is requesting read access, and output stream access is requesting write access). Should the application not be granted the appropriate read or write access to the file or file system by the profile authorization scheme, a java.lang.SecurityException is thrown.

    Try this codelet and check on emulator, by changing permission see the SOP's if it works then try on the device.

    thanks,
    ~Amitabh

  10. #10
    Regular Contributor
    Join Date
    Jan 2009
    Posts
    103

    Re: How shall i display an message "Required Application permission not granted" ??

    Quote Originally Posted by im2amit View Post
    Your code --


    Lets try changing it to as under:

    The security model is also applied during use of the returned FileConnection, specifically when the methods openInputStream(), openDataInputStream(), openOutputStream(), and openDataOutputStream() are invoked. These methods have implied request for access rights (i.e. input stream access is requesting read access, and output stream access is requesting write access). Should the application not be granted the appropriate read or write access to the file or file system by the profile authorization scheme, a java.lang.SecurityException is thrown.

    Try this codelet and check on emulator, by changing permission see the SOP's if it works then try on the device.

    thanks,
    ~Amitabh
    thanks for the reply i will try this

  11. #11
    Regular Contributor
    Join Date
    Jan 2009
    Posts
    103

    Re: How shall i display an message "Required Application permission not granted" ??

    Quote Originally Posted by im2amit View Post
    Your code --


    Lets try changing it to as under:

    The security model is also applied during use of the returned FileConnection, specifically when the methods openInputStream(), openDataInputStream(), openOutputStream(), and openDataOutputStream() are invoked. These methods have implied request for access rights (i.e. input stream access is requesting read access, and output stream access is requesting write access). Should the application not be granted the appropriate read or write access to the file or file system by the profile authorization scheme, a java.lang.SecurityException is thrown.

    Try this codelet and check on emulator, by changing permission see the SOP's if it works then try on the device.

    thanks,
    ~Amitabh
    now only after the content written into file its showing null pointer exception .
    security exception is solved by putting try catch for all the file handling code but this after writing content into file its showing null pointer exception .

  12. #12
    Nokia Developer Champion
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    3,087

    Re: How shall i display an message "Required Application permission not granted" ??

    after writing content into file its showing null pointer exception
    What are you trying to do after writing content into file --- (when its showing null pointer exception) ?

    Some variable might not be checked for null and used, put a try catch there also to identify what is null this time.... or cut&paste the suspected code block.

    thanks,
    ~Amitabh

Similar Threads

  1. Start an application and send message
    By symbi4n_programmer in forum Symbian
    Replies: 7
    Last Post: 2009-07-10, 07:12
  2. Replies: 1
    Last Post: 2008-05-08, 12:32
  3. Application embedding in WAP push message.
    By tej007 in forum Digital Rights Management & Content Downloading
    Replies: 0
    Last Post: 2008-02-18, 09:24
  4. display a popup from background application
    By alice77 in forum Symbian
    Replies: 1
    Last Post: 2006-01-31, 05:23
  5. "Not found" message when starting an application
    By Nokia_Archive in forum Symbian User Interface
    Replies: 1
    Last Post: 2002-05-30, 12:40

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×