版本适配

版本适配

这里列举了部分需要开发中进行适配的功能变更

Android 6.0

运行时权限:用户可直接在运行时管理应用权限

Android 7.0

多窗口支持

FileProvider

功能适配

Android8.0 允许安装未知来源权限

public void onInstall(View view) {
    AndPermission.with(this)
                 .runtime()
                 .permission(Permission.Group.STORAGE)
                 .onGranted(new Action<List<String>>() {
                     @Override
                     public void onAction(List<String> data) {
                         installApp();
                     }
                 })
                 .onDenied(new Action<List<String>>() {
                     @Override
                     public void onAction(List<String> data) {
                     }
                 }).start();
}

private void installApp() {
    File file = new File(Environment.getExternalStorageDirectory(), "0/1.apk");
    if(!file.exists()) {
        Toast.makeText(InstallAppActivity.this, "文件不存在", Toast.LENGTH_SHORT).show();
        return;
    }

    if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        boolean yes = getPackageManager().canRequestPackageInstalls();
        if(!yes) {
            Uri packageURI = Uri.parse("package:" + getPackageName());
            Intent intent = new Intent(Settings.ACTION_MANAGE_UNKNOWN_APP_SOURCES, packageURI);
            startActivityForResult(intent, INSTALL_PERMISS_CODE);            } else {
            realInstallApk(file);
        }
    } else {
        realInstallApk(file);
    }
}

private void realInstallApk(File file) {
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        String authority = getPackageName() + ".fileprovider";
        Uri contentUri = FileProvider
                .getUriForFile(getApplicationContext(), authority, file);
        intent.setDataAndType(contentUri, "application/vnd.android.package-archive");
    } else {
        intent.setDataAndType(Uri.fromFile(file),
                "application/vnd.android.package-archive");
    }
    startActivity(intent);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
    if(resultCode == RESULT_OK && requestCode == INSTALL_PERMISS_CODE) {
        realInstallApk(new File(Environment.getExternalStorageDirectory(), "0/1.apk"));
    }
    super.onActivityResult(requestCode, resultCode, data);
}

Android 8: 画中画模式,通知优化

Android 10:

  • 手势导航‌:轻压屏幕边缘内划可拉出应用抽屉

  • 折叠屏支持:优化多任务处理和屏幕适配

Android 11:

  • 分区存储强制执行:应用需将敏感数据(如照片、视频)存储在公共目录,其他应用无法直接访问,需通过FileProvider等机制共享

  • 一次性权限:允许用户临时授权位置、麦克风、摄像头等敏感权限,下次启动时需重新授权

Last updated