6
A
回答
7
這是你可以做什麼:
- 使用ApplicationManager.getForegroundProcessId()
- 使用ApplicationManager.getVisibleApplications()來獲取所有正在運行的應用
- 使用ApplicationManager.getProcessId()搜索應用程序進程的ID
在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); } } }
相關問題
- 1. 短信監聽黑莓應用程序和後臺應用程序?
- 2. Facebook應用程序進入前臺後
- 3. WinJs後臺應用程序
- 4. iphone後臺應用程序
- 5. VB.NET後臺應用程序
- 6. 開始活動不會將應用程序帶到前臺
- 7. 用於後臺應用程序的Facebook應用程序認證
- 8. 開始播放框架應用程序後退出控制檯
- 9. 如何檢查應用程序是否在前臺或後臺
- 10. 如何從前臺應用程序切換到後臺代理?
- 11. 如何將ios應用程序從後臺前臺
- 12. 應用程序從後臺進入前臺
- 13. 程序在後臺打開應用程序
- 14. 如何在後臺運行BlackBerry應用程序
- 15. 在後臺運行BlackBerry PhoneGap應用程序
- 16. 如何使用後臺應用程序?
- 17. 讓應用程序在前臺運行
- 18. 哪個應用程序在前臺?
- 19. 將應用程序置於前臺
- 20. 從後臺應用程序中打開帶有url方案的應用程序
- 21. 意圖當應用程序在後臺時立即打開應用程序-Android
- 22. Facebook應用程序平臺開發
- 23. NSURLConnection開始後,應用程序會轉到後臺,應用程序恢復時它會繼續嗎?
- 24. iPhone應用程序在後臺
- 25. 應用程序不在後臺工作
- 26. HTTP POST到後臺應用程序
- 27. 在後臺運行應用程序IntentService
- 28. 我的應用程序在後臺
- 29. Android,在後臺運行應用程序
- 30. 在後臺運行android應用程序?
感謝您的答覆... 相反,那麼這是沒有任何監聽器API或任何類型的事件 ,通過它,我們將獲得當前調用的前臺應用程序。 – 2009-12-28 12:35:01
如果您的應用程序,您可以隨時使用http://www.blackberry.com/developers/docs/4.5.0api/net/rim/device/api/system/Application.html#activate%28%29事件..但在其他情況下,我看不到任何選擇。 – 2009-12-28 15:15:32
好的,謝謝你的回覆 – 2009-12-29 07:15:00