1

I want create icon over screen that just listen for touch on it (without forced to create useless notification) after 3 days search over web and ask in IRC channels and implement must examples like this:

Android app that runs on top of ALL other apps?

Creating a system overlay window (always on top)

i found there is a hacky way to do this, but no one know it (except Smart Taskbar developers) i install Smart Taskbar with most source examples and found this examples killed without notification bar , but smart taskbar never killed ,(i found you can't even kill it with regular task killer, like Android Task Manager) , there is just one way to kill this icon , go to settings> apps> select smart taskbar >Force stop.

another thing that i found is that it never go to background and in android task manager (in real time process list) it is marked as visible and you can't kill it can someone help me how can i create an icon that are always visible and never killed over screen

Community
  • 1
  • 1
hosein
  • 519
  • 5
  • 25

2 Answers2

1

Call setupNotification() in your service's onCreate method and clearNotification() in your service's onDestroy method.

private int SERVICE_NOTIFICATION = 1; // this should be unique for your app

private void setupNotification()
{
    if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2){
        Notification serviceNotification = new NotificationCompat.Builder(this)
            .setContentTitle("Your Service")
            .setContentText("Your Service is running in the background")
            .setSmallIcon(R.drawable.ic_launcher)
            .setPriority(NotificationCompat.PRIORITY_MIN)
            .setOngoing(true)
            .build();
        startForeground(SERVICE_NOTIFICATION, serviceNotification);
    }
    else{
        Notification serviceNotification = new Notification();
        serviceNotification.flags = Notification.FLAG_ONGOING_EVENT;
        startForeground(SERVICE_NOTIFICATION, serviceNotification);
    }
}

private void clearNotification()
{
    stopForeground(true);
}
Simon
  • 10,932
  • 50
  • 49
  • sorry , but that make notification, but what i said is that i don't need useless notification anyway, like above answer, this is not useful response – hosein May 04 '14 at 12:53
  • This is exactly what Smart Taskbar 2 does. Did you even try it? It's an invisible notification on less than APIv18. After that you must have notification. – Simon May 04 '14 at 12:54
0

This is absolutely doable. You should keep an always running service. and in on create of that service,

@Override
    public void onCreate() {
        super.onCreate();

        customView= new MYCustomView(MyService.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;
        WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE);
        wm.addView(customView, params);
    }

This will place your view on top of all vies.

Rahul
  • 1,169
  • 1
  • 12
  • 27
  • did you ever test what you post anyway,No, you must create notification for foreground service , please read post carefully, it goes to background and stop sometime – hosein Apr 29 '14 at 07:45
  • I had implemented this in one of my projects. Yes you would need to keep a notification for foreground service since you may want to keep that service alive – Rahul Apr 29 '14 at 07:50
  • And inorder to restart the service if it gets killed, you may need startSticky() as well. – Rahul Apr 29 '14 at 07:53
  • ok, i asked for what smart taskbar developer does(no notification) , so your code in this post is unrelated, – hosein Apr 29 '14 at 08:04