Android Service 弹出系统全局Dialog
2016-09-06 00:18
351 查看
在Android Service中弹出全局Dialog对话框
搜了下资料,全部是:
增加权限
代码调试了无数遍就是不能弹出对话框,也不报错。
其实最主要在于在主线程中调用Dialog方法。
如此,便可以顺利调出系统全局Dialog。
搜了下资料,全部是:
<code class="hljs avrasm has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: "Source Code Pro", monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">dialog<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.getWindow</span>()<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.setType</span>(WindowManager<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.LayoutParams</span><span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.TYPE</span>_SYSTEM_ALERT)<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">; </span></code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right: 1px solid rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li></ul>
增加权限
<code class="hljs xml has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: "Source Code Pro", monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><span class="hljs-tag" style="color: rgb(0, 102, 102); box-sizing: border-box;"><<span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">uses-permission</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">android:name</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"android.permission.SYSTEM_ALERT_WINDOW"</span> /></span> </code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right: 1px solid rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">2</li></ul>
代码调试了无数遍就是不能弹出对话框,也不报错。
其实最主要在于在主线程中调用Dialog方法。
<code class="hljs java has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: "Source Code Pro", monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">Handler handler = <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">new</span> Handler(Looper.getMainLooper()); handler .post(<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">new</span> Runnable() { <span class="hljs-annotation" style="color: rgb(155, 133, 157); box-sizing: border-box;">@Override</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">public</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">void</span> <span class="hljs-title" style="box-sizing: border-box;">run</span>() { <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">//调用dialog }</span> });</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right: 1px solid rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li></ul>
如此,便可以顺利调出系统全局Dialog。
相关文章推荐
- Android 获取栈顶activity并在service 中弹出全局dialog解决方法
- Android菜鸟笔记-Service中弹出对话框,即全局性质Dialog不依赖于Activity
- android在Service中弹出Dialog对话框,即全局性对话框
- android在Service中弹出Dialog对话框,即全局性对话框
- Android 小米手机限制系统弹出dialog
- android在Service中弹出Dialog对话框,即全局性对话框
- android service Dialog 弹出框
- Android service启动dialog对话框 全局对话框
- android service 如何弹出dialog
- Android 弹出全局dialog
- [Android]后台Service 弹出自定义dialog
- Android在Service中弹出Dialog
- 在Android中捕获Application全局异常 阻止系统弹出强制退出的对话框
- android在Service,BroadCast onReceiver()中弹出Dialog对话框,即全局性对话框
- android在Service中弹出Dialog对话框,即全局性对话框
- android在Service中弹出Dialog对话框
- android在Service中弹出Dialog对话框,即全局性对话框
- Android在Service中弹出对话框(Dialog)
- 弹出系统dialog或者在service里面显示dialog
- android service中弹出dialog对话框