2014年3月3日星期一

show recent app list in android

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import android.app.Activity;
import android.os.Bundle;
import android.os.IBinder;
import android.os.RemoteException;

public class RecentAppsActivity extends Activity {

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_recent_apps);

try {
Class serviceManagerClass;
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();
}

finish();
}

}

没有评论:

发表评论