それはあなたにとって遅い答えですが、他の誰かを救うことができるかもしれません... :)
Permission : android.permission.SYSTEM_ALERT_WINDOW
class ScreenOverlayService extends Service {
HUDView mView;
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Log.i("onStartCommand", "called....");
// return android.app.Service.START_STICKY; // don't kill service...
return START_NOT_STICKY;
}
@Override
public void onCreate() {
super.onCreate();
mView = new HUDView(this);
WindowManager.LayoutParams params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH,
PixelFormat.TRANSLUCENT);
params.gravity = Gravity.RIGHT | Gravity.TOP;
params.setTitle("Load Average");
WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE);
wm.addView(mView, params);
}
@Override
public void onDestroy() {
super.onDestroy();
if(mView != null){
((WindowManager) getSystemService(WINDOW_SERVICE)).removeView(mView);
mView = null;
}
}
class HUDView extends ViewGroup {
private Paint mLoadPaint;
Context context;
public HUDView(Context context_)
{
super(context_);
context = context_;
mLoadPaint = new Paint();
mLoadPaint.setAntiAlias(true);
mLoadPaint.setTextSize(10);
mLoadPaint.setARGB(255, 255, 0, 0);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
//canvas.drawText("Hello World", 5, 15, mLoadPaint);
// Read the image
Bitmap markerImage = BitmapFactory.decodeResource(getResources(), R.drawable.pic1);
// Draw it, centered around the given coordinates
canvas.drawBitmap(markerImage,
screenPoint.x - markerImage.getWidth() / 2,
screenPoint.y - markerImage.getHeight() / 2, null);
}
@Override
protected void onLayout(boolean arg0, int arg1, int arg2, int arg3, int arg4) {
}
@Override
public boolean onTouchEvent(MotionEvent event) {
return super.onTouchEvent(event);
}
}
}