Hi,
I am trying to dispatch key-event to other activity from a dialog, I
am trying to add a dialog in WindowManagerSerivce.java file in
frameworks/base/services/java/com/android/server, to display this
dialog i am using the following snippet to get SystemContext


ActivityThread at = ActivityThread.currentActivityThread();
        if (at == null) {
            Looper.prepare();
            at = ActivityThread.systemMain();
        }
        if(at != null){
            sysContext = at.getSystemContext();
            Log.d(TAG, "SystemContext = " + sysContext);
        }
Dialog dialog = new Dialog(sysContext);
 
dialog.setContentView(com.android.internal.R.layout.<my_Custom_layout>);
                dialog.setTitle("Custom Dialog");
                dialog.show();

but i can't able to display the dialog



When i tried to launch activity as a dialog (@android:style/
Theme.Dialog) using intent, for the same, activity is displayed as
dialog. fine, now what i am trying is i want to dispatch keyevent when
you press a button in the dialog displayed, i am using handler to pass
the messages to WindowManagerService, where it will dispatch the
keyevent and even i get the pid of top activity and pass the same to
dispatchKey() method in WindowManagerService.java,  dispatchKey
returns '1' which means the key is dispatched successfully. what
actually i am doing is when you press a button in the dialog, i will
pass a message to handler implemented in WindowManagerService.java
say, DISPATCH_BACK_KEY, and i am able to get proper PID from the
activity manager

packageName =
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;
                        }
                    }
public void handleMessage(Message msg) {
switch (msg.what) {

case 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;
}

Key is dispatched successfully, but the activity beyond the my-dialog
displayed is still visible. please help me how can i proceed to
dispatch back key to the activity beyond my-dialog..


Thanks in advance

-- 
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

Reply via email to