3

I have tried out everything I know and can find, but still I cannot get my alert dialog to show as a TYPE_SYSTEM_ALERT. It shows on my app when I open it, but it does not pop up if my app is not on front.

I've got:

final AlertDialog.Builder d = new AlertDialog.Builder(this);
d.setTitle("App name");
d.setMessage("Message");
d.setPositiveButton("OK", null);
d.setIcon(R.drawable.ic_launcher);

AlertDialog dialog = d.create();
dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
d.show();

And then I have in manifest:

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

What am I missing??

The function flow before this alert is following:

  1. Broadcast receiver listens for incoming sms messages.
  2. Once received, it passes the message to a function in MainActivity using "RunOnUIThread".
  3. The message is parsed and the alert dialog is shown. Now why the TYPE_SYSTEM_ALERT is not working?? I can see from logcat that the message is parsed ok but still alert dialog is not showing up as system alert. Anyone?
Bill the Lizard
  • 398,270
  • 210
  • 566
  • 880
raki
  • 53
  • 1
  • 8
  • Where you are using current code in Activity or in Service? – ρяσѕρєя K Apr 23 '15 at 04:53
  • I'm using it from Activity. – raki Apr 24 '15 at 03:43
  • One thing I'm wondering. OS should never close the app for two reasons: 1. I have bound it to a fore ground service so according to android lifecycle specs it should not get easily closed. 2. For testing purposes there is also an active wake lock. Regardless of these facts I can still see onPause and onStop called!? On the other hand, the app seems to handle incoming messages just fine even though it's on background and "stopped". Weird... – raki Apr 24 '15 at 03:49

1 Answers1

0

The required permission is only for system apps:

<permission android:name="android.permission.SYSTEM_ALERT_WINDOW" 
   android:protectionLevel=
   "signature|preinstalled|appop|pre23|development"/>
barkside
  • 3,951
  • 4
  • 23
  • 32