public void showRecentlyApp() {
Class serviceManagerClass;
try {
serviceManagerClass = Class.forName("android.os.ServiceManager");
Method getService = serviceManagerClass.getMethod("getService",
String.class);
IBinder retbinder = (IBinder) getService.invoke(
serviceManagerClass, "statusbar");
Class statusBarClass = Class.forName(retbinder
.getInterfaceDescriptor());
Object statusBarObject = statusBarClass.getClasses()[0].getMethod(
"asInterface", IBinder.class).invoke(null,
new Object[] { retbinder });
Method clearAll = statusBarClass.getMethod("toggleRecentApps");
clearAll.setAccessible(true);
clearAll.invoke(statusBarObject);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (RemoteException e) {
e.printStackTrace();
}
}
利用反射方法实现打开“最近任务”
最新推荐文章于 2024-05-02 19:57:38 发布
本文介绍了一种通过反射机制调用Android系统的ServiceManager类和服务的方法,实现显示最近使用过的应用程序列表的功能。该方法利用了ServiceManager获取statusbar服务,并进一步通过statusBar服务调用toggleRecentApps方法来触发显示最近使用的应用程序。
742

被折叠的 条评论
为什么被折叠?



