从我的黑莓应用程序打开shazam

时间:2011-03-22 14:36:24

标签: blackberry blackberry-eclipse-plugin blackberry-jde shazam

如果安装了代码,我需要打开shazam代码(手机中其他已安装的应用程序)。 如何检查手机中是否安装了shazam,如果安装了如何从我的应用程序中打开它?如果有任何人有想法请帮助。谢谢你。

1 个答案:

答案 0 :(得分:2)

public static ApplicationDescriptor getApplicationDescriptor(String appName) {
    try {
        int[] moduleHandles = CodeModuleManager.getModuleHandles();
        if (moduleHandles != null && moduleHandles.length > 0) {
            for (int i = 0; i < moduleHandles.length; i++) {
                ApplicationDescriptor[] applicationDescriptors = CodeModuleManager.getApplicationDescriptors(moduleHandles[i]);
                if (applicationDescriptors != null && applicationDescriptors.length > 0) {
                    for (int j = 0; j < applicationDescriptors.length; j++) {
                        if (applicationDescriptors[j].getModuleName().toLowerCase().equals(appName.toLowerCase())) {
                            return applicationDescriptors[j];
                        }
                    }
                }
            }
        }
    } catch (Exception e) {
        System.out.println("error at getApplicationDescriptor" + e);
    }
    return null;
}

public static int runApplication(String appName) {
    int processId = -1;
    ApplicationDescriptor appDescriptor = getApplicationDescriptor(appName);
    if (appDescriptor != null) {
        //is not null Application installed
        processId = ApplicationManager.getApplicationManager().getProcessId(appDescriptor);
        if (processId == -1) {
            // -1 if application has no process (i.e. is not running).
            try {
                processId = ApplicationManager.getApplicationManager().runApplication(appDescriptor);
            } catch (ApplicationManagerException e) {
                e.printStackTrace();
            }
        }
    }
    return processId;
}

调用像

这样的runApplication
int pid=-1;
    if((pid=runApplication(appName))>-1){
            //application running
            System.out.println(appName +" runing with process id "+pid);
        }