Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Contributor
Posts: 22
Registered: ‎10-05-2012
My Device: 9800
My Carrier: 0
Accepted Solution

While use camera in my application close current screen

Hi

 

I am creating a application for uploading Images form camera and gallary,

1) if i press camera button in my app i want to capture image and show that image to current screen.

2)currenltly i'm using the below functioin to do that, but at first use of the app user is asked to give permission to use camera after that if we allow then the current screen is closed. before that it is capturing the image.

3) If the use the same app after exiting second time there is no closing of the current screen and it working fine.

 

Any suggestions. can we give permissions like the usage of camera even before installing app like in android permissions.

 

The function i used is

 

public void uploadPhotoFromCamera(final int flagg) {
                final FileSystemJournalListener listener = new FileSystemJournalListener()
                {
                      long lastUSN;
                      long a=lastUSN;
                      public void fileJournalChanged()
                      {
                            try {
                                  Thread.sleep(50);
                            } catch (InterruptedException e) {
                                  // TODO Auto-generated catch block
                                  e.printStackTrace();
                            }
                            long USN = FileSystemJournal.getNextUSN();
                            outer: for (long i = USN - 1; i >= lastUSN; --i)
                            {
                                  FileSystemJournalEntry entry = FileSystemJournal.getEntry(i);
                                  if (entry != null)
                                  {
                                        if (entry.getEvent() == FileSystemJournalEntry.FILE_ADDED)
                                        {
                                              if (entry.getPath().indexOf(".jpg") != -1)
                                              {
                                                    lastUSN = USN;
                                                    photoPath = entry.getPath();
                                                    try
                                                    {
                                                          boolean acceptance=false;
                                                          ApplicationPermissionsManager apm = ApplicationPermissionsManager.getInstance();
                                                          ApplicationPermissions original = apm.getApplicationPermissions();

                                                          ApplicationPermissions permRequest = new ApplicationPermissions();
                                                          if(original.getPermission(ApplicationPermissions.PERMISSION_INPUT_SIMULATION) != ApplicationPermissions.VALUE_ALLOW)
                                                          {
                                                                permRequest.addPermission(ApplicationPermissions.PERMISSION_INPUT_SIMULATION);
                                                                //permRequest.addPermission(ApplicationPermissions.PERMISSION_AUTHENTICATOR_API);
                                                                //permRequest.addPermission(ApplicationPermissions.PERMISSION_EVENT_INJECTOR);
                                                                acceptance = ApplicationPermissionsManager.getInstance().invokePermissionsRequest(permRequest);
                                                          }
//                                                      
                                                          EventInjector.KeyEvent inject = new EventInjector.KeyEvent(EventInjector.KeyEvent.KEY_DOWN,Characters.ESCAPE,  50);
                                                          EventInjector.invokeEvent(inject);
                                                          EventInjector.invokeEvent(inject);
                                                          EventInjector.invokeEvent(inject);

                                                          if(photoPath != null) {
                                                            //here i am using that picture from that path
                                                           }
                                                     

                                                    }catch      (Exception e){
                                                          RIMLogger.getInstance("TraceCRM").error("############## Capture photo Error >>"+e.getMessage()+"<<");
                                                    }

                                                    break outer;
                                              }
                                        }
                                  }
                            }
                            lastUSN = USN;
                      }
                };

                UiApplication.getUiApplication().addFileSystemJournalListener(listener);
                Invoke.invokeApplication(Invoke.APP_TYPE_CAMERA, new CameraArguments(CameraArguments.ARG_CAMERA_APP));
}
         

 

Thanks

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: While use camera in my application close current screen

Ask for permission before you go into this - see

ApplicationPermissionsDemo

Contributor
Posts: 22
Registered: ‎10-05-2012
My Device: 9800
My Carrier: 0

Re: While use camera in my application close current screen

Thanks

I solved that issues now its working fine

 

 

 

 

Thanks