Android Question simulate long press home button to open recent apps

intera

Member
Licensed User
Longtime User
Hi guys , thanks for this amazing forum...here it goes my first thread....

according this:
http://stackoverflow.com/questions/14267482/android-programmatically-open-recent-apps-dialog

it is posible with this code:
B4X:
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);

any reflection guru can translate for a newbie ?
thanks in advanced
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
You are challenging me :)

B4X:
Sub ToggleRecentApps
   Dim r As Reflector
   r.Target = r.RunStaticMethod("android.os.ServiceManager", "getService", Array As Object("statusbar"), _
     Array As String("java.lang.String"))
   r.Target = r.RunStaticMethod("com.android.internal.statusbar.IStatusBarService$Stub", "asInterface", _
     Array As Object(r.Target), Array As String("android.os.IBinder"))
   r.RunMethod("toggleRecentApps")
End Sub
 
Upvote 0

intera

Member
Licensed User
Longtime User
Works like a charm!!!!Amazing!! thanks a lot:D
Now I will have to study how you did it!!!
 
Upvote 0
Top