如果安装了代码,我需要打开 shazam(手机中的其他安装应用程序)。如何检查手机中是否安装了 shazam,如果已安装,如何从我的应用程序中打开它?如果有人有想法,请提供帮助。提前致谢。
问问题
239 次
1 回答
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);
}
于 2011-03-23T08:20:27.887 回答