创建一个应用程序,它会锁定另一个应用程序事件 [英] Create an application which will lock another application event
问题描述
其实我想让这将getGlobalEvent和控制通过其他自定义应用程序事件的应用程序。有没有什么办法这样做。我可以从一个特定的应用程序获得全球盛会?它像一个应用程序,它会在你的黑莓锁定自定义应用程序,如果在锁定的应用程序列表中添加下面的应用程序,并把密码才能访问,然后当u尝试打开该应用程序,它会问ü在锁定应用程序设置密码。
Actually I want to make an application which will getGlobalEvent and control that event through another custom application. Is there any way to do so. Can i get global event from a particular application? Its like an application which will lock custom application in your blackberry, if you add following application in that locking app list and put password to access then when u try to open that application, it will ask for a password which u set in the locking app.
推荐答案
- 这应该是后台应用程序
- in计时器线程检查当前前台应用程序
- 使用自定义全局模式对话框要求密码
- 如果密码错误关闭App / A>或移动应用背景
不得不说,可以有多个进程一个应用程序中,所以我们将进行检查基于组件的名称:
Have to say, there can be several processes within one application so we will perform check based on module name:
private String getModuleNameByProcessId(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].getModuleName();
break;
}
}
return result;
}
移动应用背景?
是的,在<一个没有requestBackground() href=\"http://www.blackberry.com/developers/docs/4.7.0api/net/rim/device/api/system/ApplicationManager.html\"相对=nofollow> ApplicationManager ...所以你可以做的是<一个href=\"http://www.blackberry.com/developers/docs/4.7.0api/net/rim/device/api/system/ApplicationManager.html#requestForeground%28int%29\"相对=nofollow> requestForeground(),其上是不能在前景中的下一个最佳应用,而这将主动应用移动到背景!你甚至可以打开主屏幕,<一个href=\"http://www.blackberry.com/developers/docs/4.7.0api/net/rim/device/api/system/ApplicationManager.html#requestForegroundForConsole%28%29\"相对=nofollow> requestForegroundForConsole():
Move application to Background?
Yep, there's no requestBackground() in ApplicationManager... so what you can do is requestForeground() on the next best app which is not on foreground, and this will move active app to background! You can even bring up Home Screen with requestForegroundForConsole():
protected int switchForegroundModule() {
int id = -1;
ApplicationManager appMan = ApplicationManager.getApplicationManager();
ApplicationDescriptor appDes[] = appMan.getVisibleApplications();
for (int i = 0; i < appDes.length; i++) {
if (!appDes[i].getModuleName().equalsIgnoreCase(STR_MODULE_NAME)) {
id = appMan.getProcessId(appDes[i]);
appMan.requestForeground(id);
// give a time to foreground application
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
break;
}
}
return id;
}
全球对话
只需输入密码,您可以扩展对话框,它会更容易消耗的结果:
Global Dialog
Just to input password you can extend Dialog, it will be easier to consume result:
class PaswordDialog extends Dialog {
private BasicEditField mPwdField = new BasicEditField();
public PaswordDialog() {
super(Dialog.D_OK_CANCEL, "Enter password", Dialog.CANCEL, null,
Dialog.FIELD_HCENTER);
add(mPwdField);
}
public String getPassword() {
return mPwdField.getText();
}
}
和密码检查将是这样的:
And password check will look like:
private boolean checkPassword() {
boolean result = false;
final PaswordDialog pwdDlg = new PaswordDialog();
invokeAndWait(new Runnable() {
public void run() {
Ui.getUiEngine().pushGlobalScreen(pwdDlg, 0,
UiEngine.GLOBAL_MODAL);
}
});
result = ((Dialog.OK == pwdDlg.getSelectedValue()) && pwdDlg
.getPassword().equalsIgnoreCase(STR_PASSWORD));
return result;
}
将这个一起
样来阻止ADRESS图书应用程序:
Put this all together
Sample to block Adress Book App:
public class LockMainApp extends Application {
private static final String STR_MODULE_NAME = "net_rim_bb_addressbook_app";
private static final String STR_PASSWORD = "12345";
int mFGProcessId = -1;
public LockMainApp() {
Timer timer = new Timer();
timer.schedule(mCheckForeground, 1000, 1000);
}
public static void main(String[] args) {
LockMainApp app = new LockMainApp();
app.enterEventDispatcher();
}
TimerTask mCheckForeground = new TimerTask() {
public void run() {
int id = ApplicationManager
.getApplicationManager().getForegroundProcessId();
if (id != mFGProcessId) {
mFGProcessId= id;
String moduleName = getModuleNameByProcessId(mFGProcessId);
if (moduleName.equalsIgnoreCase(STR_MODULE_NAME)) {
if (!checkPassword())
mFGProcessId = switchForegroundModule();
}
}
};
};
}
这篇关于创建一个应用程序,它会锁定另一个应用程序事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!