Popup in any application

I want a popup dialog at a specific time in any application of my code:

public class testPOPDialog extends Activity { /** Called when the activity is first created. */ private Handler mHandler = new Handler(); @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mHandler.postDelayed(mUpdateTimeTask, 1000); } private Runnable mUpdateTimeTask = new Runnable() { public void run() { AlertDialog d = new AlertDialog.Builder(testPOPDialog.this) .setTitle("tanchulai") .setMessage("bucuo de tanchulai") .create(); d.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT); d.show(); } }; } 

let me

 12-03 10:12:18.162: ERROR/AndroidRuntime(571): android.view.WindowManager$BadTokenException: Unable to add window android.view.ViewRoot$W@43dd71c0 -- permission denied for this window type 

what is this permission if I remove d.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT); my application is correct .....

+7
android android widget
Dec 03 '10 at 10:18
source share
3 answers

Add this permission to your manifest:

 android.permission.SYSTEM_ALERT_WINDOW 
+14
Dec 03 '10 at 10:45
source share

First of all, thanks to Mathias Lin

I'm new to Android, so it was hard for me to set the resolution knowing from Mathias Lin 's answer. Because I did not know how to set the resolution and where in the manifest file.

Finally, I did this with a Mathias Lin answer. So I made the answer in detail.




In the mainfest file use

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

after

 <uses-sdk android:minSdkVersion=... android:targetSdkVersion=... /> 

but

 <uses-sdk android:minSdkVersion="7" android:targetSdkVersion="16" /> <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/> 
+1
Mar 11 '14 at 8:58
source share

try this in your manifest file with the activity you want to show as a popup window .-- β†’ android: theme = "@android: style / Theme.Dialog"

0
Dec 03 '10 at 10:22
source share



All Articles