2009-12-28 3 views

답변

7

이것은 당신이 무엇을 할 수 있습니다 :

  • 사용 ApplicationManager.getForegroundProcessId()
  • 사용 ApplicationManager.getVisibleApplications() 프로세스 ID에 의해
  • 사용 ApplicationManager.getProcessId() 앱 검색 할 실행중인 모든 응용 프로그램을 얻을
  • 이 작업은 TimerTask에 정의 된 기간이 있음

    답장을 보내 주셔서
    public class AppListenerApp extends Application { 
    int mForegroundProcessId = -1; 
    
    public AppListenerApp() { 
        Timer timer = new Timer(); 
        timer.schedule(mCheckForeground, 2000, 2000);      
    } 
    
    public static void main(String[] args) { 
        AppListenerApp app = new AppListenerApp(); 
        app.enterEventDispatcher(); 
    } 
    
    TimerTask mCheckForeground = new TimerTask() { 
        public void run() { 
         int id = getForegroungProcessID(); 
         if(id != mForegroundProcessId) 
         { 
          mForegroundProcessId = id; 
          String name = 
           getAppNameByProcessId(mForegroundProcessId); 
          showMessage(name); 
         } 
        }; 
    }; 
    
    private int getForegroungProcessID() { 
        return ApplicationManager.getApplicationManager() 
          .getForegroundProcessId(); 
    } 
    
    private String getAppNameByProcessId(int id) { 
        String result = null; 
        ApplicationManager appMan = 
           ApplicationManager.getApplicationManager(); 
        ApplicationDescriptor appDes[] = 
           appMan.getVisibleApplications(); 
        for (int i = 0; i < appDes.length; i++) { 
         if (appMan.getProcessId(appDes[i]) == id) { 
          result = appDes[i].getName(); 
          break; 
         } 
        } 
        return result; 
    } 
    
    private void showMessage(String message) { 
        synchronized (Application.getEventLock()) { 
         Dialog dlg = new Dialog(Dialog.D_OK, message, 
             Dialog.OK, null, Manager.FIELD_HCENTER); 
         Ui.getUiEngine() 
             .pushGlobalScreen(dlg, 1, UiEngine.GLOBAL_QUEUE); 
        } 
    } 
    } 
    
+0

감사합니다 ... 오히려 다음이 어떤 리스너 API 또는 우리가 현재 호출 된 전경 응용 프로그램을 얻을 것이다 통해 이벤트 의 모든 종류가 있습니다. –

+0

애플리케이션 인 경우 언제든지 http://www.blackberry.com/developers/docs/4.5.0api/net/rim/device/api/system/Application.html#activate%28%29 이벤트를 사용할 수 있습니다. 다른 경우에는 옵션이 없습니다. –

+0

답장을 보내 주셔서 감사합니다. –

관련 문제