在android oreo上以编程方式显示最近的应用程序

在android oreo上以编程方式显示最近的应用程序,android,android-recents,android-8.0-oreo,Android,Android Recents,Android 8.0 Oreo,我想以某种方式插入最近的应用程序硬按钮,点击该按钮打开本机android最近的应用程序屏幕 我目前从事以下工作: boolean success = showRecents1(c); if (!success) { showRecents2(c); } 这在很多设备上都有效,但在android oreo模拟器上却不起作用。有人知道一个同样适用于android oreo的解决方案吗 private boolean showRecents1(Context c) { try {

我想以某种方式插入最近的应用程序硬按钮,点击该按钮打开本机android最近的应用程序屏幕

我目前从事以下工作:

boolean success = showRecents1(c);
if (!success) {
    showRecents2(c);
}
这在很多设备上都有效,但在android oreo模拟器上却不起作用。有人知道一个同样适用于android oreo的解决方案吗

private boolean showRecents1(Context c) {
    try {
        Intent intent = new Intent("com.android.systemui.recent.action.TOGGLE_RECENTS");
        intent.setComponent(new ComponentName("com.android.systemui", "com.android.systemui.recent.RecentsActivity"));
        c.startActivity(intent);
        return true;
    } catch (Exception e) {
        L.e(e);
    }
    return false;
}

private boolean showRecents2(Context c) {
    try {
        Class 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);
        return true;
    } catch (Exception e) {
        L.e(e);
    }
    return false;
}

在android 10中不起作用。这里有一个潜在的替代方案-