Show Dialog Box In Another Application And Bring On Front On Top Of Other Application
Solution 1:
ActivityManagermanager= (ActivityManager) getApplicationContext().getSystemService(ACTIVITY_SERVICE);
// get the context from the currently running task
List< ActivityManager.RunningTaskInfo > taskInfo = manager.getRunningTasks(1);
Contextcontext= taskInfo.get(0).topActivity;
I'm not too sure if this actually works for activities that are not from your application, but I haven't got the resources to test it myself at the moment, before adding this as answer. It's worth a try if you actually are able to retrieve the current top activity with this. I just hope my memory gave me the right syntax...
Solution 2:
Actually, you need to add following permission to your manifest file to achieve what you want: android.permission.SYSTEM_ALERT_WINDOW
http://developer.android.com/reference/android/Manifest.permission.html#SYSTEM_ALERT_WINDOW
Answer on following StackOverflow thread provides an example of how to do this: Having application running above other app
Solution 3:
You can achieve this using WindowManager
, the application which receives the data should have a background service
. If you are posting a broadcast event to pass data to other application, then when the application receives the data , start a service to display the dialog.
The dialog
can be a custom dialog , which need to be added as a view to WindowManager
Ok, Here is a sample with a custom dialog. You can try same approach with the default AlertDialog
When the application receive the event , start the service and In Service
when onStartCommand
called , show the dialog.
Follow this steps…..
Get the instance of WindowManager
WindowManagerwindowManager= (WindowManager) getSystemService(WINDOW_SERVICE);
Inflate the custom view
ViewdialogView= View.inflate(getBaseContext(),R.layout.dialog_layout,null);
Add listener to the view.
dialogView.setOnClickListener(newView.OnClickListener() {
@OverridepublicvoidonClick(View v) {
windowManager.removeView(dialogView);
dialogView = null;
}
});
Set Window manager params
WindowManager.LayoutParams params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.TYPE_PHONE,
WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD,
PixelFormat.TRANSLUCENT);
params.gravity = Gravity.CENTER | Gravity.CENTER;
Add the view to Window Manager
windowManager.addView(dialogView, params);
Also add SYSTEM_ALERT_WINDOW
permission in manifest
<uses-permissionandroid:name="android.permission.SYSTEM_ALERT_WINDOW" />
Post a Comment for "Show Dialog Box In Another Application And Bring On Front On Top Of Other Application"