【问题标题】:Closing the Camera Application from a T/P Application从 T/P 应用程序关闭相机应用程序
【发布时间】:2012-09-20 06:07:58
【问题描述】:

我的问题...我已经从我的第三方应用程序访问了相机应用程序,然后我拍照。然后我转到菜单并添加了一个菜单项 (MENUITEM_CAMERA_PREVIEW) 。我的菜单项必须执行一项功能,一旦完成,我希望我的应用程序在打开相机应用程序之前关闭相机并打开上一个屏幕。

我面临与此线程相同的问题: http://supportforums.blackberry.com/t5/Java-Development/How-to-exit-camera-app-properly/m-p/1924127#M209092

有人可以告诉我他们了解解决方案吗,如果不了解,您可能知道解决方案,非常感谢您的帮助。

我看过这些帖子: Closing the default camera in Blackberry programatically after taking a picture

http://supportforums.blackberry.com/t5/Java-Development/Unable-to-close-camera-using-EventInjector-for-touch-screen/m-p/785247#M143879

How to exit a blackberry application from another application programatically?

但我不确定我应该添加什么才能从第三方应用程序退出相机应用程序。

谁能帮我理解一下....

【问题讨论】:

    标签: java blackberry camera exit


    【解决方案1】:

    尝试从您的应用中关闭相机应用很棘手。我不知道有什么干净的方法,但是I have done it this way

    基本上,您的应用需要请求权限

    ApplicationPermissions.PERMISSION_INPUT_SIMULATION
    

    注入击键。然后它将模拟 ESC 键的按下,这是用户将/可以手动关闭相机应用程序的方式。为了使这种技术更可靠,我需要让代码(有条件地)多次注入 ESC 键。

    我让这个更可靠的方法是我的应用中有一个Screen,它在我启动相机应用之前显示。然后我监视该屏幕以查看它何时再次暴露。当我检测到它已经暴露时,我认为我必须注入 足够 ESC 键序列来关闭相机(或者我猜用户可能自己按下了 ESC,回到我的应用程序)。

    更新: 根据下面的评论,这是我在此解决方案中使用的一些附加代码,通过监视下面我的一个屏幕的 exposed 状态来检测相机是否正确关闭它:

    private boolean _isExposed = false;
    
    protected void onExposed() {
        super.onExposed();
        _isExposed = true;
    }
    
    protected void onObscured() {
        super.onObscured();
        _isExposed = false;
    }
    
    public boolean isExposed() {
        return _isExposed;
    }
    

    如果您愿意,您还可以将 _isExposed 设置为 false 以首先打开相机应用程序。

    【讨论】:

    • 谢谢你,一旦我尝试了这个方法,我会给你反馈。
    • 我收到一条错误消息,提示“MainScreen 类型的方法 'isExposed()' 未定义”我应该将它添加到我不扩展 MainScreen 的类中吗?
    • @Nequita,我用添加的代码更新了我的答案。 isExposed() 是我添加的一个方法,所以这就是你得到编译错误的原因。请记住投票和/或接受适合你的答案。谢谢。
    【解决方案2】:

    这是我最终使用的代码,它好多了。

    public class MyScreen extends MainScreen{
    Player _p;
    VideoControl _videoControl;  
    FileConnection fileconn;
    String PATH;
    String GetfileName;
    LabelField GetPhotofileName = new LabelField("",LabelField.FOCUSABLE){
        protected boolean navigationClick(int status, int time){
            Dialog.alert("Clicked");
        return true;
        }
     };
    
     public static boolean SdcardAvailabulity() {
         String root = null;
         Enumeration e = FileSystemRegistry.listRoots();
         while (e.hasMoreElements()) {
             root = (String) e.nextElement();
             if( root.equalsIgnoreCase("sdcard/") ) {
                 return true;
             }else if( root.equalsIgnoreCase("store/") ) {
                 return false;
             }
         }
         class MySDListener implements FileSystemListener {
             public void rootChanged(int state, String rootName) {
                 if( state == ROOT_ADDED ) {
                     if( rootName.equalsIgnoreCase("sdcard/") ) {
                     }
                 } else if( state == ROOT_REMOVED ) {
                 }
             }
         }
         return true;
     }
     protected boolean invokeAction(int action){
         boolean handled = super.invokeAction(action); 
         if(SdcardAvailabulity()){
               PATH = System.getProperty("fileconn.dir.memorycard.photos")+"Image_"+System.currentTimeMillis()+".jpg";//here "str" having the current Date and Time;
         } else {
             PATH = System.getProperty("fileconn.dir.photos")+"Image_"+System.currentTimeMillis()+".jpg"; 
         }
         if(!handled){
             if(action == ACTION_INVOKE){   
                 try{                      
                     byte[] rawImage = _videoControl.getSnapshot(null);
                     fileconn=(FileConnection)Connector.open(PATH);
                     if(fileconn.exists()){
                        fileconn.delete();
                     }
                     fileconn.create();
                     OutputStream os=fileconn.openOutputStream();
                     os.write(rawImage);
                     GetfileName =fileconn.getName();
                     fileconn.close();
                     os.close();
                     Status.show("Image is Captured",200);
                     GetPhotofileName.setText(GetfileName);
                     if(_p!=null)
                        _p.close();          
                 }catch(Exception e){
                    if(_p!=null){
                        _p.close();
                     }
                     if(fileconn!=null){
                        try{
                             fileconn.close();
                         }catch (IOException e1){ 
                         }
                     }                    
                 }
             }
          }           
          return handled;                
      }
     public MyScreen(){
         setTitle("Camera App");
         try{
            _p = javax.microedition.media.Manager.createPlayer("capture://video?encoding=jpeg&width=1024&height=768");
            _p.realize();
            _videoControl = (VideoControl) _p.getControl("VideoControl");
            if (_videoControl != null){
                Field videoField = (Field) _videoControl.initDisplayMode (VideoControl.USE_GUI_PRIMITIVE, "net.rim.device.api.ui.Field");
                _videoControl.setDisplayFullScreen(true);
                 _videoControl.setVisible(true);
                _p.start();
                if(videoField != null){
                    add(videoField);
                }
            } 
         }catch(Exception e){
             if(_p!=null) {
                 _p.close();
             }
             Dialog.alert(e.toString());
         }   
         add(GetPhotofileName);
     }
    }
    

    【讨论】:

      猜你喜欢
      • 2014-04-23
      • 2012-09-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多