I sit, for example, in Skype ... And here comes a message Viber over cyp. Or even the screen of the phone is extinguished, still the window of the vibe will appear ...

What mechanism is used?

  • The answer must be checked ... In this case, you need a little time ... - sitev_ru

1 answer 1

I do not know how in Viber, but this can be done using the usual AlertDialog

register in the manifest permission to display system windows

<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>

Software unlock requires permission

<uses-permission android:name="android.permission.DISABLE_KEYGUARD"/>

Before displaying the dialog, put a flag to the window

dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);

And that's all.

You can play with this example.

 public class LocalService extends Service { Handler handler = new Handler(); @Override public int onStartCommand(Intent intent, int flags, int startId) { init(); return START_STICKY; } @Nullable @Override public IBinder onBind(Intent intent) { return null; } private void init(){ handler.postDelayed(task, 10000); } Runnable task = new Runnable() { @Override public void run() { showDialog(); handler.postDelayed(this, 10000); } }; private void showDialog(){ KeyguardManager keyguardManager = (KeyguardManager)getSystemService(Activity.KEYGUARD_SERVICE); KeyguardManager.KeyguardLock lock = keyguardManager.newKeyguardLock(KEYGUARD_SERVICE); lock.disableKeyguard(); AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setMessage("Test"); builder.setNegativeButton("Cancel", null); AlertDialog dialog = builder.create(); dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT); dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON); dialog.show(); } } 

You will receive an alert every 10 seconds whether the application is launched independently or not.

Do not leave the phone with the service running :-)

  • Will it work with a locked screen? - sitev_ru
  • This is another story. Before displaying, you need to unlock the screen programmatically, look at your Viber resolution. In general, this is not a best, imagine you put the bodies in your pocket, the application pulls, unlocks and chases away. Now if you unlock the phone, the dialogue is the first thing you see. - SorryForMyEnglish
  • But the vibeer works on this principle ... How can I unlock the screen programmatically? - sitev_ru
  • How much does it cost to make money? - sitev_ru
  • added unlock - SorryForMyEnglish