Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I had the same problem and here if how i solved it. At first time i've tried to use Android's native <code>PopupWindow</code> class, but later i decided to use <code>WindowManager</code> like this way :</p> <pre><code>public class MyService extends Service { private View mView; private WindowManager.LayoutParams mParams; private WindowManager mWindowManager; @Override public void onCreate() { super.onCreate(); mView = new MyLoadView(this); mParams = new WindowManager.LayoutParams( WindowManager.LayoutParams.MATCH_PARENT, 150, 10, 10, WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL, PixelFormat.TRANSLUCENT); mParams.gravity = Gravity.CENTER; mParams.setTitle("Window test"); mWindowManager = (WindowManager)getSystemService(WINDOW_SERVICE); mWindowManager.addView(mView, mParams); } @Override public IBinder onBind(Intent intent) { return null; } @Override public void onDestroy() { super.onDestroy(); ((WindowManager)getSystemService(WINDOW_SERVICE)).removeView(mView); mView = null; } public class MyLoadView extends View { private Paint mPaint; public MyLoadView(Context context) { super(context); mPaint = new Paint(); mPaint.setTextSize(50); mPaint.setARGB(200, 200, 200, 200); } @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); canvas.drawText("test test test", 0, 100, mPaint); } @Override protected void onAttachedToWindow() { super.onAttachedToWindow(); } @Override protected void onDetachedFromWindow() { super.onDetachedFromWindow(); } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); } } } </code></pre> <p>And you can call this service class via intent :</p> <pre><code>intent = new Intent(mContext, MyService.class); if (intent != null) { getContext().startService(intent); } </code></pre> <p>Also, set permission in your manifest file :</p> <pre><code>&lt;uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" /&gt; </code></pre> <p>I referenced Android's <code>LoadAverageService.java</code> class, and i finally created a popup window from service! This is a very simple example, so you might need to add something more if you want to develop complex functions. Hope this will help you and others.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload