2

working on blackberry OS7 9850 device

i am working to Turn on Flash as Light on Blackberry.

i have successfully completed this, but in BBOS6 device 9780 video field is showing; how can i hide that video field?

here is my code

private FlashControl flashControl;
private VideoControl _videoControl;
private Field _videoField;
private ButtonField capture;
private Field videoField;

    // Set the displayed title of the screen       
    public MyScreen(int j) {


        try {

            Player player = javax.microedition.media.Manager.createPlayer("capture://video?encoding=video/3gpp");

            player.realize();

            VideoControl videoControl = (VideoControl) player.getControl("VideoControl");
            if(videoControl != null)
            {
                videoField = (Field)videoControl.initDisplayMode( VideoControl.USE_GUI_PRIMITIVE, "net.rim.device.api.ui.Field" );
                try
                {

                    videoControl.setDisplaySize(1, 1);
                }
                catch(Exception e)
                {

                }
                //videoControl.setDisplaySize( 0 , 0 );
                videoControl.setVisible(true);
                videoField.setBackground(BackgroundFactory.createSolidBackground(0x000000));
                //videoField.
                add(videoField);

                flashControl = (FlashControl)player.getControl("javax.microedition.amms.control.camera.FlashControl");
                setFlashlight(true);
            }
            player.start();
        } catch (Exception e) {
            System.out.println(e);
        }
    }

    private void setFlashlight(boolean b) {

        if(b == true){
            flashControl.setMode(FlashControl.FORCE);
        }
        else{
            flashControl.setMode(FlashControl.OFF);
        }
    }

is there any solution, like we can push the screen or video field in the background?

Nate
  • 31,017
  • 13
  • 83
  • 207
askquestion
  • 171
  • 1
  • 14

1 Answers1

2

There is (at least) one app on BlackBerry World (e.g. One Touch Flashlight) that does this, and it almost certainly accomplishes this task in the following way (instead of using VideoControl and FlashControl):

  1. The app programmatically opens the native Camera app
  2. Using keystroke injection, the app injects touch events to turn on the camera's flash
  3. The app then requests the foreground back (Application#requestForeground()), so that it covers up the Camera app.
  4. When you close the app, it overrides Screen#onClose() and takes the opportunity to inject another Characters.ESCAPE key event, which also closes out the Camera app, which was simply behind the foregrounded "flashlight" app.

You can search Stack Overflow for other examples of opening Camera from your app, using keystroke injection, and requesting your app be brought to the foreground.

References

https://stackoverflow.com/a/6559836/119114

https://stackoverflow.com/a/1298900/119114

http://www.blackberry.com/go/toucheventinjectorsampleapp

Community
  • 1
  • 1
Nate
  • 31,017
  • 13
  • 83
  • 207
  • thanks for giving suggestion any how i have manage to hide video field for few second by giving this code UiApplication.getUiApplication().invokeLater(new Runnable() { public void run() { UiApplication.getUiApplication().pushScreen(new nextscreen()); } }, 100, false); now i want to close current screen after turning flash light on how can i do this. – askquestion Feb 11 '14 at 13:25
  • and this is nextscreen clas public nextscreen() { setBackground(BackgroundFactory.createSolidTransparentBackground(Color.BLACK, 250)); } protected void paint(net.rim.device.api.ui.Graphics graphics) { super.subpaint(graphics); } – askquestion Feb 11 '14 at 13:26
  • @askquestion, please don't post new questions down here in comments. Your comments don't seem to have anything to do with the solution I suggested in my answer. You are free to post new questions if you like. Please also don't paste unformatted code into comments. I can't read that. Can you? – Nate Feb 12 '14 at 06:16