开发者

Want to run my application as service in Blackberry

I have one application which has no UI. When my phone will boot up, this application should start running automatically. It means there is no need to click any icon. The application will start like a service. How can i do this? Please reply.

This is my code...

public class BlockApplication extends Application { int mForegroundProcessId = -1;

public BlockApplication() {
    Timer timer = new Timer();
    timer.schedule(mCheckForeground, 1000, 1);                       
}


public static void main(String[] args) {
    BlockApplication app = new BlockApplication();
    app.enterEventDispatcher();
}


TimerTask mCheckForeground = new TimerTask() {
    public void run() {
        int id = getForegroungProcessID();
        if(id != mForegroundProcessId)
        {
            mForegroundProcessId =开发者_JS百科 id;
            String name = getAppNameByProcessId(mForegroundProcessId);
                KeyEvent inject = new KeyEvent(KeyEvent.KEY_DOWN, Characters.ESCAPE, 0);
       inject.post();
                }
    };
};


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].getLocalizedName();
            break;
        }
    }
    return result;
}

}

Thanks in advance.


The application needs to be a system module. With the Eclipse plugin you should go to the App Descriptor and check the box that says "Do not display the application icon on the BlackBerry home screen".

Using the BB Ant tools it looks like you should set the systemmodule attribute in the jdp tag to true.


If you use Blackberry Ant Tools

http://bb-ant-tools.sourceforge.net/

In the jdp tag, set these attributes... runonstartup="true" startuptier="7"

That will arrange your app to start when the device resets. If you use the Eclipse plugin there should be similar config somewhere.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜