参考链接:https://www.jianshu.com/p/271bbd13bfcf
安卓 10
开始分区,每一个程序有自己的私有目录,在这个目录里读取、写入文件不需要权限
api File file=content.getExternalFileDir("文件夹目录") File file1=new File(file.getAbsolutePath,"文件名") 在自己私有目录生成了文件,但是如果不写入流,文件不可见。且如果在该目录下有同名文件夹,文件会生成失败
安卓8
安卓8对悬浮框的修改做了一些修改
参考链接 https://blog.csdn.net/LoveDou0816/article/details/79172637
在使用SYSTEM_ALERT_WINDOW权限弹出悬浮窗的应用无法在使用以下窗口类型来弹出悬浮窗
WindowManager.LayoutParams.TYPE_PRIORITY_PHONE WindowManager.LayoutParams.TYPE_PHONE WindowManager.LayoutParams.TYPE_SYSTEM_ERROR WindowManager.LayoutParams.TYPE_SYSTEM_ALERT WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY
把悬浮窗的type设置成 TYPE_APPLICATION_OVERPLAY
服务
参考链接 https://blog.csdn.net/Haienzi/article/details/81268022
在安卓8中前台服务的申请发生了改变
8.0生成Notification需要为notification设置一个渠道,通过渠道id
private Notification getNotification() { Notification.Builder builder = new Notification.Builder(this); // .setContentTitle("投屏服务") // // .setContentText("投屏服务正在运行..."); //设置Notification的ChannelID,否则不能正常显示 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { builder.setChannelId(notificationId); } Notification notification = builder.build(); return notification; }
通过,notificationManager来生成渠道
private void startForegroundService() { notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); //创建•NotificationChannel if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { NotificationChannel channel = new NotificationChannel(notificationId, notificationName, NotificationManager.IMPORTANCE_HIGH); notificationManager.createNotificationChannel(channel); } startForeground(1, getNotification()); }
开启前台服务
8.0之前 startService(new Intent(this,Service.class))
8.0之后 startForegroundService(new Intent(this,Service.class))
停止前台服务
调用 stopForeground(true)移除正在运行的前台服务