自动安装

在Android7.0自动安装做出了修改,android8.0增加了权限

//以前 Intent intent = new Intent(); intent.setAction(Intent.ACTION_VIEW); intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive"); startActivity(intent);
//android 7.0需要用到共享文件provider的方式,不能识别file://需要将其转为uriIntent intent = new Intent();intent.setAction(Intent.ACTION_VIEW);intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);Uri contentUri = FileProvider.getUriForFile(context, "com.zjhc.jxzq.jxzq.fileprovider", file); intent.setDataAndType(contentUri, "application/vnd.android.package-archive"); startActivity(intent); //AndroidManifist.xml中配置    //res下新建xml目录,新建file_paths.xml文件<?xml version="1.0" encoding="utf-8"?>    注意:保存路径需要新建apk目录,Environment.getExternalStorageDirectory()对应external-path
//android8.0需要写入权限//权限校验  boolean b =getPackageManager().canRequestPackageInstalls();  if(!b){       ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.REQUEST_INSTALL_PACKAGES}, 1000); }

开启服务

android 8.0开启前台服务,正对startService()更改成使用startForegroundService()。
现场保活时,系统对电量进行了进一步的优化,如果不考虑点亮可以尝试将应用加入电量优化的白名单

  if(Build.VERSION.SDK_INT>= Build.VERSION_CODES.O){            PowerManager powerManager = (PowerManager) activity.getSystemService(POWER_SERVICE);            boolean hasIgnored = powerManager.isIgnoringBatteryOptimizations(activity.getPackageName());            //  判断当前APP是否有加入电池优化的白名单,如果没有,弹出加入电池优化的白名单的设置对话框。            if (!hasIgnored) {                Intent intent = new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);                intent.setData(Uri.parse("package:" + activity.getPackageName()));                activity.startActivity(intent);            }        }

8.0使用startForegroundService需要配一个Notification,不然报Context.startForegroundService() did not then call Service.startForeground()错误

更多相关文章

  1. Android 改变屏幕亮度时需添加权限
  2. 初学Android,电池电量提示(七十五)
  3. Android 获取手机电量信息
  4. Android应用程序获取ROOT权限代码
  5. Android uses-permission 权限大全
  6. Android获取系统应用及安装应用的权限列表
  7. 如何在Android 11 中正确请求位置权限?以及Android 8 - 11位置权
  8. android M上可能需要开发者注意的权限大全

随机推荐

  1. android微信api登录的接入
  2. 在用Kivy开发Python手机游戏时通过Plyer
  3. Android(安卓)ThreadPoolExecutor线程池
  4. android 对话框对于返回值的处理
  5. Android-APP启动优化
  6. Dagger2的化简学习总结
  7. Android(安卓)效率开发之图片---Glide 旋
  8. Android(安卓)利用重力感应调整手机模式
  9. 酒浓码浓 - ios/android微信浏览器video
  10. Android自定义控件实现滑动开关效果