When user start the application, I just want to show a button. User can continiue to use phone .
Example : (problem is icon is not clickable)
android:theme="#android:style/Theme.Translucent.NoTitleBar.Fullscreen"
http://developer.android.com/reference/android/Manifest.permission.html#SYSTEM_ALERT_WINDOW
"android.permission.SYSTEM_ALERT_WINDOW" use this permission in main-feast
windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
Button btn = new ImageView(this);
WindowManager.LayoutParams params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.TYPE_PHONE,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
PixelFormat.TRANSLUCENT);
windowManager.addView(btn, params);
Related
Goodmorning,
i'm developing an overlay which is posted by a service.
The problem is that the screen stays always on, even after screeen timeout expires.
This is my code:
WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE);
WindowManager.LayoutParams params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY,
WindowManager.LayoutParams.TYPE_STATUS_BAR|WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
PixelFormat.TRANSLUCENT);
params.gravity= Gravity.TOP | Gravity.LEFT;
overlay.setKeepScreenOn(false);
wm.addView(overlay, params);
I've already tried to add WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON, but no luck.
Thanks for your help.
The solution is not to use WindowManager.LayoutParams.TYPE_STATUS_BAR
but one with lower privileges as this is only used by the system.
I have implemented chat head kind of pop up for my application using service. And I have used edit text inside that.
But problem is that when I click on edit text only cursor is visible and keyboard is not coming up. And not even able to select or copy paste the text inside that edit text. Any help? Thanks
I found solution to my problem.
I was using the following code earlier:-
Global variables:-
private WindowManager mWindowManager;
WindowManager.LayoutParams params;
Then in onCreate of Service
mWindowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
//Add the view to the window.
params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.TYPE_PHONE,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
PixelFormat.TRANSLUCENT);
Problem was with FLAG_NOT_FOCUSABLE, use FLAG_NOT_TOUCH_MODAL instead.
But now again problem was that though I was able to get the keyboard with my floatingView but keypad was not coming for other apps, even back button stopped working.
So to fix this I used button on Floating UI which toggles between enabling keypad on floating UI and disabling that so that back button and keypad works for other apps.
I used the following code for the same:-
private void enableKeyPadInput(Boolean enable) {
mWindowManager.removeViewImmediate(mFloatingView);
if (enable) {
params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.TYPE_PHONE,
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL,
PixelFormat.TRANSLUCENT);
} else {
params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.TYPE_PHONE,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
PixelFormat.TRANSLUCENT);
}
mWindowManager.addView(mFloatingView, params);
}
If true is passed to this method then keypad starts working. If false is passed then other apps starts working.
This is my workaround for the problem. Is there any other way to achieve the same which is better than this?
thank #Narendra Jadon
this maybe better
private void enableKeyPadInput(Boolean enable) {
//mWindowManager.removeView(mFloatingView);
if (enable) {
params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY,
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL,
PixelFormat.TRANSLUCENT);
} else {
params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
PixelFormat.TRANSLUCENT);
}
mWindowManager.updateViewLayout(mFloatingView,params);
//mWindowManager.addView(mFloatingView, params);
}
I am writing an android library that needs to display an activity on top of the client app. After some reading up it seems that adding a new window is what I want to do so I added in this permission.
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
I then try to add an image view by doing this
windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
WindowManager.LayoutParams params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
PixelFormat.TRANSLUCENT);
params.gravity = Gravity.BOTTOM | Gravity.LEFT;
params.x = 10;
params.y = 100;
ImageView imageview = new ImageView(this);
imageview.setImageResource(R.drawable.avatar);
windowManager.addView( imageview , params);
But what I want is to have my own activity on this new window on top of the client apps window. is this even possible? How would I do this?
Ok the correct approach to this appears to be to inflate the layout with in the service class and add it to the windowmanager that way. Then create a regular java class that can be used as the event listeners for the actions within that layout. I didnt need to use fragments or activities.
mRootLayout = (LinearLayout) LayoutInflater.from(context).
inflate(R.layout.myContainerXML, null);
MyListManager myListManager = new MyListManager(mRootLayout,context);
WindowManager.LayoutParams params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.TYPE_PHONE,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,
PixelFormat.TRANSLUCENT);
ListView listView = (ListView) mRootLayout.findViewById(R.id.listView);
final MyListAdapter adapter = new MyListAdapter(activity,R.layout.list_row,(ArrayList)myListManager.getList());
listView.setAdapter(adapter);
windowManager.addView(mRootLayout, params);
If anyone has a better way I would love to hear it thanks
I want to implement notifications like the one in the following image.
Notification appears any time. I think it's of course a background service waiting for new messages from the server then shows this. What I think this is an activity implemented as dialog with this custom UI. Am I correct? And is it a normal startActivity method from the service? And how do I do the transition animation to make it appears slowly from left to right with zooming when show up?
Check out this link http://www.piwai.info/chatheads-basics. He provides information about how to add them on your screen.
The trick is to add a View to the WindowManager like following code
private WindowManager windowManager;
private ImageView chatHead;
public void addView()
{
windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
chatHead = new ImageView(this);
chatHead.setImageResource(R.drawable.android_head);
WindowManager.LayoutParams params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.TYPE_PHONE,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
PixelFormat.TRANSLUCENT);
params.gravity = Gravity.TOP | Gravity.LEFT;
params.x = 0;
params.y = 100;
windowManager.addView(chatHead, params);
}
Don't forget to add the permission <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
I have a WindowManager set up like this.
myWindowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
final WindowManager.LayoutParams params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.FILL_PARENT,
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
PixelFormat.TRANSLUCENT);
myWindowManager.addView(view, params);
I add a View object to a WindowManager like this. I want to move this WindowManager to the TOP Center. I am not sure how I can do this. Any ideas?
You can set Gravity for you view. i.e.
myWindowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
final WindowManager.LayoutParams params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.FILL_PARENT,
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
PixelFormat.TRANSLUCENT);
//edited
params.gravity=Gravity.TOP|Gravity.CENTER_HORIZONTA;
myWindowManager.addView(view, params);
You can also check this for more details.