यह वह जगह है आप क्या कर सकते:
- उपयोग 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);
}
}
}
स्रोत
2009-12-28 10:53:58
उत्तर के लिए धन्यवाद ... बल्कि तो यह कोई श्रोता एपीआई या घटना के किसी भी प्रकार के माध्यम से जो हम वर्तमान लागू अग्रभूमि ऐप्लिकेशन मिल जाएगा है। –
यदि आपका आवेदन है, तो आप हमेशा http://www.blackberry.com/developers/docs/4.5.0api/net/rim/device/api/system/Application.html#activate%28%29 ईवेंट का उपयोग कर सकते हैं .. लेकिन अन्य मामलों में मुझे कोई विकल्प नहीं दिखता है। –
ठीक उत्तर के लिए धन्यवाद –