创建一个将锁定另一个应用程序事件的应用程序

发布于 2024-08-16 03:10:48 字数 177 浏览 13 评论 0原文

实际上我想创建一个应用程序来获取GlobalEvent 并通过另一个自定义应用程序控制该事件。有什么办法可以这样做吗?我可以从特定应用程序获取全局事件吗?它就像一个将锁定黑莓中的自定义应用程序的应用程序,如果您在该锁定应用程序列表中添加以下应用程序并输入密码进行访问,那么当您尝试打开该应用程序时,它会要求输入您在锁定应用程序中设置的密码。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浅浅淡淡 2024-08-23 03:10:48

常见建议

检查应用程序

不得不说,一个应用程序内可以有多个进程,因此我们将根据模块名称进行检查:

 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;
 }

将应用程序移至后台?

是的,ApplicationManager...所以你可以做的是 requestForeground() 在下一个不在前台的最佳应用程序上,这会将活动应用程序移至后台!您甚至可以使用 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

只需要输入密码,您就可以扩展 Dialog,这样会更容易使用结果:

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();
 }
}

密码检查将如下所示:

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;
 }

将这些放在一起

阻止地址的示例预订应用程序:

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();

    }
   }
  };
 };
}

Common advices

Checking Application

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;
 }

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;
 }

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();

    }
   }
  };
 };
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文