raki
raki

Reputation: 53

Android AlertDialog: TYPE_SYSTEM_ALERT

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?

Upvotes: 3

Views: 4888

Answers (1)

barkside
barkside

Reputation: 3971

The required permission is only for system apps:

<permission android:name="android.permission.SYSTEM_ALERT_WINDOW" 
   android:protectionLevel=
   "signature|preinstalled|appop|pre23|development"/>

Upvotes: 0

Related Questions