android targetSdkVersion / alertdialog pop error when running on 6.0+
16lz
2021-12-04
while pop up one alert dialog in service, for sdk <=19, only required permission in manifest
then set dialog dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
is success.
but for sdk > 23 android 6.0 ++ , it failed.
we need require permission when your app first time run, then reply permissoin
if (!Settings.canDrawOverlays(this)) { Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + getPackageName())); this.startActivity(intent); dialogConnectLost.getWindow().setType(WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY);} else { dialogConnectLost.getWindow().setType(WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY);}
BUT , another way to fix that is keep your targetSdkVersion <23, it will work as on sdk below 23. and
you just keep old code no need change.
no matter your buid sdk of project is >23 or not.
this is what targetSdkVersion 's magic effect.
included: build sdk >= 23 , then app could run on android 6.0++, keep target sdk < 23, then app could run like old sdk.
更多相关文章
- 代码中设置drawableleft
- android 3.0 隐藏 系统标题栏
- Android开发中activity切换动画的实现
- Android(安卓)学习 笔记_05. 文件下载
- Android中直播视频技术探究之—摄像头Camera视频源数据采集解析
- 技术博客汇总
- android 2.3 wifi (一)
- AndRoid Notification的清空和修改
- Android中的Chronometer