[android-developers] Re: programatically press a button
hey, Please tell me about http://davanum.wordpress.com/2007/12/19/android-simulate-key-strokes/. How they did it On Feb 14, 7:17 pm, Mark Murphy mmur...@commonsware.com wrote: saru wrote: Hey i want to write a program in android to press menu button or end button or answer button automatically. You can't, sorry. -- Mark Murphy (a Commons Guy)http://commonsware.com|http://twitter.com/commonsguy Android Consulting/App Development:http://commonsware.com/consulting -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: programatically press a button
Hi saru, I posted the same question last Friday. I found the solution which consists on dispatching the event using the event dispatcher of the activity. If you would like to read some advanced technical details about event processing you can read this excellent post: http://letsgoustc.spaces.live.com/blog/cns!89AD27DFB5E249BA!488.entry public void onClick(View v) { new Thread(new Runnable() { @Override public void run() { KeyEvent backEvtDown = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_BACK); KeyEvent backEvtUp = new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_BACK); mActivity.dispatchKeyEvent(backEvtDown); mActivity.dispatchKeyEvent(backEvtUp); } }).start(); } Best Regards, On 15 fév, 10:28, saru sarucs...@gmail.com wrote: hey, Please tell me abouthttp://davanum.wordpress.com/2007/12/19/android-simulate-key-strokes/. How they did it On Feb 14, 7:17 pm, Mark Murphy mmur...@commonsware.com wrote: saru wrote: Hey i want to write a program in android to press menu button or end button or answer button automatically. You can't, sorry. -- Mark Murphy (a Commons Guy)http://commonsware.com|http://twitter.com/commonsguy Android Consulting/App Development:http://commonsware.com/consulting -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
Re: [android-developers] Re: programatically press a button
Well, the two things I can tell you about it is: 1) They show exactly how they did it by giving you the source code. 2) They don't show you how to programatically send Menu or End Call button presses, because it is not possible to simulate those buttons (as Mark stated already). Those hardware buttons are restricted to application developers, you can't simulate them. You also can't end *any* active call from your app, which is what the End Call button obviously does. The one thing you can do is make your options menu appear without requiring the menu button (I've not tested this): http://groups.google.com/group/android-developers/browse_thread/thread/7c04ceb0baf32750/49df915f430d8f84?lnk=stq=#49df915f430d8f84 But this does not involve simulating key presses. On Mon, Feb 15, 2010 at 9:28 AM, saru sarucs...@gmail.com wrote: hey, Please tell me about http://davanum.wordpress.com/2007/12/19/android-simulate-key-strokes/. How they did it On Feb 14, 7:17 pm, Mark Murphy mmur...@commonsware.com wrote: saru wrote: Hey i want to write a program in android to press menu button or end button or answer button automatically. You can't, sorry. -- Mark Murphy (a Commons Guy)http://commonsware.com|http://twitter.com/commonsguy Android Consulting/App Development:http://commonsware.com/consulting -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: programatically press a button
I had exactelly the same problem as you and using that peace of code I could simulate back and home keys. On 15 fév, 10:52, Sean Hodges seanhodge...@googlemail.com wrote: Well, the two things I can tell you about it is: 1) They show exactly how they did it by giving you the source code. 2) They don't show you how to programatically send Menu or End Call button presses, because it is not possible to simulate those buttons (as Mark stated already). Those hardware buttons are restricted to application developers, you can't simulate them. You also can't end *any* active call from your app, which is what the End Call button obviously does. The one thing you can do is make your options menu appear without requiring the menu button (I've not tested this): http://groups.google.com/group/android-developers/browse_thread/threa... But this does not involve simulating key presses. On Mon, Feb 15, 2010 at 9:28 AM, saru sarucs...@gmail.com wrote: hey, Please tell me abouthttp://davanum.wordpress.com/2007/12/19/android-simulate-key-strokes/. How they did it On Feb 14, 7:17 pm, Mark Murphy mmur...@commonsware.com wrote: saru wrote: Hey i want to write a program in android to press menu button or end button or answer button automatically. You can't, sorry. -- Mark Murphy (a Commons Guy)http://commonsware.com|http://twitter.com/commonsguy Android Consulting/App Development:http://commonsware.com/consulting -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: programatically press a button
I had exactelly the same problem as you. Using that piece of code I could simulate Home and Back key events. Regards, On 15 fév, 10:52, Sean Hodges seanhodge...@googlemail.com wrote: Well, the two things I can tell you about it is: 1) They show exactly how they did it by giving you the source code. 2) They don't show you how to programatically send Menu or End Call button presses, because it is not possible to simulate those buttons (as Mark stated already). Those hardware buttons are restricted to application developers, you can't simulate them. You also can't end *any* active call from your app, which is what the End Call button obviously does. The one thing you can do is make your options menu appear without requiring the menu button (I've not tested this): http://groups.google.com/group/android-developers/browse_thread/threa... But this does not involve simulating key presses. On Mon, Feb 15, 2010 at 9:28 AM, saru sarucs...@gmail.com wrote: hey, Please tell me abouthttp://davanum.wordpress.com/2007/12/19/android-simulate-key-strokes/. How they did it On Feb 14, 7:17 pm, Mark Murphy mmur...@commonsware.com wrote: saru wrote: Hey i want to write a program in android to press menu button or end button or answer button automatically. You can't, sorry. -- Mark Murphy (a Commons Guy)http://commonsware.com|http://twitter.com/commonsguy Android Consulting/App Development:http://commonsware.com/consulting -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
Re: [android-developers] Re: programatically press a button
The back button is fine, but you can't simulate the exact behaviour of the home button. For example, bringing up the recent apps menu when long pressing it. Good work-around for some scenarios though. On Mon, Feb 15, 2010 at 10:36 AM, Houcem Berrayana houcem.berray...@gmail.com wrote: I had exactelly the same problem as you. Using that piece of code I could simulate Home and Back key events. Regards, On 15 fév, 10:52, Sean Hodges seanhodge...@googlemail.com wrote: Well, the two things I can tell you about it is: 1) They show exactly how they did it by giving you the source code. 2) They don't show you how to programatically send Menu or End Call button presses, because it is not possible to simulate those buttons (as Mark stated already). Those hardware buttons are restricted to application developers, you can't simulate them. You also can't end *any* active call from your app, which is what the End Call button obviously does. The one thing you can do is make your options menu appear without requiring the menu button (I've not tested this): http://groups.google.com/group/android-developers/browse_thread/threa... But this does not involve simulating key presses. On Mon, Feb 15, 2010 at 9:28 AM, saru sarucs...@gmail.com wrote: hey, Please tell me abouthttp://davanum.wordpress.com/2007/12/19/android-simulate-key-strokes/. How they did it On Feb 14, 7:17 pm, Mark Murphy mmur...@commonsware.com wrote: saru wrote: Hey i want to write a program in android to press menu button or end button or answer button automatically. You can't, sorry. -- Mark Murphy (a Commons Guy)http://commonsware.com|http://twitter.com/commonsguy Android Consulting/App Development:http://commonsware.com/consulting -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: programatically press a button
For a long press you should make the thread sleeping for a while until the recent apps appears. I haven't yet tested the menu, and phone calls buttons. On 15 fév, 11:47, Sean Hodges seanhodge...@googlemail.com wrote: The back button is fine, but you can't simulate the exact behaviour of the home button. For example, bringing up the recent apps menu when long pressing it. Good work-around for some scenarios though. On Mon, Feb 15, 2010 at 10:36 AM, Houcem Berrayana houcem.berray...@gmail.com wrote: I had exactelly the same problem as you. Using that piece of code I could simulate Home and Back key events. Regards, On 15 fév, 10:52, Sean Hodges seanhodge...@googlemail.com wrote: Well, the two things I can tell you about it is: 1) They show exactly how they did it by giving you the source code. 2) They don't show you how to programatically send Menu or End Call button presses, because it is not possible to simulate those buttons (as Mark stated already). Those hardware buttons are restricted to application developers, you can't simulate them. You also can't end *any* active call from your app, which is what the End Call button obviously does. The one thing you can do is make your options menu appear without requiring the menu button (I've not tested this): http://groups.google.com/group/android-developers/browse_thread/threa... But this does not involve simulating key presses. On Mon, Feb 15, 2010 at 9:28 AM, saru sarucs...@gmail.com wrote: hey, Please tell me abouthttp://davanum.wordpress.com/2007/12/19/android-simulate-key-strokes/. How they did it On Feb 14, 7:17 pm, Mark Murphy mmur...@commonsware.com wrote: saru wrote: Hey i want to write a program in android to press menu button or end button or answer button automatically. You can't, sorry. -- Mark Murphy (a Commons Guy)http://commonsware.com|http://twitter.com/commonsguy Android Consulting/App Development:http://commonsware.com/consulting -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
Re: [android-developers] Re: programatically press a button
saru wrote: hey, Please tell me about http://davanum.wordpress.com/2007/12/19/android-simulate-key-strokes/. How they did it The date on that post is from December 2007. As of December 2007, Android had been out for about a month and existed on no hardware. Android has changed a fair bit since that milestone release (M3, IIRC), and the code shown in that post will no longer run. Always check the dates of blog posts before relying on their code. Any blog post from before September 2008 will not be reliable on modern versions of Android. -- Mark Murphy (a Commons Guy) http://commonsware.com | http://twitter.com/commonsguy Android Consulting/App Development: http://commonsware.com/consulting -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: programatically press a button
hi Houcem Berrayana, thanks for sharing with me and helping me. But unfortunately i am not getting output by running your code.Can you please send me the whole sample code.if you can then please mail me.my mail id, sarucs...@gmail.com On Feb 15, 4:52 pm, Houcem Berrayana houcem.berray...@gmail.com wrote: Hi saru, I posted the same question last Friday. I found the solution which consists on dispatching the event using the event dispatcher of the activity. If you would like to read some advanced technical details about event processing you can read this excellent post:http://letsgoustc.spaces.live.com/blog/cns!89AD27DFB5E249BA!488.entry public void onClick(View v) { new Thread(new Runnable() { @Override public void run() { KeyEvent backEvtDown = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_BACK); KeyEvent backEvtUp = new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_BACK); mActivity.dispatchKeyEvent(backEvtDown); mActivity.dispatchKeyEvent(backEvtUp); } }).start(); } Best Regards, On 15 fév, 10:28, saru sarucs...@gmail.com wrote: hey, Please tell me abouthttp://davanum.wordpress.com/2007/12/19/android-simulate-key-strokes/. How they did it On Feb 14, 7:17 pm, Mark Murphy mmur...@commonsware.com wrote: saru wrote: Hey i want to write a program in android to press menu button or end button or answer button automatically. You can't, sorry. -- Mark Murphy (a Commons Guy)http://commonsware.com|http://twitter.com/commonsguy Android Consulting/App Development:http://commonsware.com/consulting -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: programatically press a button
What I would try is to create a KeyEvent object and dispatch it to the UI thread. Something like this (I haven't tried this; code below only to sketch this up on the conceptual level): KeyEvent.Callback callbackReceiver = new KeyEvent.Callback(...) { // callback code }; KeyEvent.DispatcherState dispatcherState = new KeyEvent.DispatcherState(...); myMainActivity.runOnUiThread(new Runnable() { public void run() { new KeyEvent(KeyEvent.ACTION_UP, KEYCODE_MENU).dispatch(callbackReceiver, dispatcherState, null); } } ) ; The KeyEvent defines keycode and action (key up on MENU in the example). Dispatch it and callbackReceiver should be called. But not so fast... I recommend to synchronize this through the event loop using runOnUiThread. That way, you serialize your custom-event with key events that are generated by the user. On Feb 14, 1:26 am, saru sarucs...@gmail.com wrote: Hey i want to write a program in android to press menu button or end button or answer button automatically. Please help me if you can. though i got some links likehttp://davanum.wordpress.com/2007/12/19/android-simulate-key-strokes/ BUT i am getting error because of using import android.os.ServiceManager; and import android.view.IWindowManager; as this packages can not be resolved -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en