AFAIK that is not possible... I don't think you can redirect events to other activities that you don't control. That would be a big security risk.
Thanks, Justin Anderson MagouyaWare Developer http://sites.google.com/site/magouyaware On Fri, Mar 11, 2011 at 3:44 AM, praveen kumar <[email protected] > wrote: > Hi, > I want to override the back key of the Android device to display a > dialog, > which consists of two buttons say "Back" and "Exit". when you press > the Back button > in dialog it should dispatch back key to the top activity which is > currently running, i can able to get > system context by adding following code snippet to > <android_source_directory>frameworks/ > base/services/java/com/android/server/WindowManagerService.java. > > ActivityThread at = ActivityThread.currentActivityThread(); > if (at == null) { > Looper.prepare(); > at = ActivityThread.systemMain(); > } > if(at != null){ > sysContext = at.getSystemContext(); > Log.d(TAG, "SystemContext = " + sysContext); > } > > to display the dialog i added following code > Dialog dialog = new Dialog(myContext); > dialog.setContentView(com.android.internal.R.layout.<my-layout-name>); > dialog.setTitle("Custom Dialog"); > dialog.show(); > > > Using sysContext, I can able to display toast, and I can able to > launch the activity, but > when i try to display a dialog using the same sysContext i got the > error saying, > unable to add window "window token is null" it would be great if you > give any input > why it is not able to display dialog using sysConttext? > > i added the following code, snippet to get top activity pid > > am = (ActivityManager) > myContext.getSystemService(Activity.ACTIVITY_SERVICE); > currentPackageName = > am.getRunningTasks(1).get(0).topActivity.getPackageName(); > > List<ActivityManager.RunningAppProcessInfo> processes; > processes = am.getRunningAppProcesses(); > for(ActivityManager.RunningAppProcessInfo info: processes) { > Log.i("Process:", info.processName); > if(currentPackageName.equalsIgnoreCase(info.processName)){ > Log.i(TAG, "Found !"); > mpid = info.pid; //pid of top Activity > muid = 0; // will be always 0 > } > } > > private Handler msgHandler = new Handler(){ > //this method will handle the calls from other threads. > public void handleMessage(Message msg) { > int result = -1; > switch (msg.what) { > case TPMUHelper.DISPATCH_BACK_KEY: > Log.d(TAG, "Dispatching Back_Key"); > code = KeyEvent.KEYCODE_BACK; > KeyEvent backEvent = new KeyEvent(downTime, > eventTime, > action, code, repeatCount, metaState, > deviceId, scancode, KeyEvent.FLAG_FROM_SYSTEM); > Log.i(TAG, "PID = " + mpid + ", UID = " +muid); > result = dispatchKey(backEvent, mpid, muid); > Log.d(TAG, "Dispatch Key Returns = " + result); > break; > } > } > }; > > When i send "DISPATCH_BACK_KEY" message from my-activity "Back" button > press event, it comes here > and dispatch back key, dispatchkey(KeyEvent event, int pid, int uid) > returns '1', i am success with > this, however currently running activity is not getting closed. simply > what i need is, i want to > send back key to whichever the activity is currently running, (system > application or 3rd party > application). input regarding the same is appreciated. > > Thanks & Regards > Praveen > > -- > You received this message because you are subscribed to the Google > Groups "Android Developers" group. > To post to this group, send email to [email protected] > To unsubscribe from this group, send email to > [email protected] > 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 [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

