1、API:
targetSdkVersion>=26
2、通知: 适配
3、透明主题:
fixOrientation工具类
Only fullscreen opaque activities can request orientation
代码中设置setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT);
代替:android:screenOrientation="portrait"
<item name="android:windowIsTranslucent">true</item>改为:
<item name="android:windowIsTranslucent">false</item>
<item name="android:windowDisablePreview">true</item>
4、安装权限设置:
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
5、安装文件:
public static void installApk(Context context, String path) {
if(context == null || TextUtils.isEmpty(path)){
return;
}
//更新时出现安装包解析异常:setFlags与addFlags位置顺序不对导致,应该先setFlags再使用addFlags
File apkFile = new File(path);
Intent intent = new Intent();
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setAction(Intent.ACTION_VIEW);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);//添加这一句表示对目标应用临时授权该Uri所代表的文件
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
Uri apkUri = FileProvider.getUriForFile(context, context.getPackageName()+".fileprovider", apkFile);
intent.setDataAndType(apkUri, "application/vnd.android.package-archive");
} else {
intent.setDataAndType(Uri.fromFile(apkFile), "application/vnd.android.package-archive");
}
context.startActivity(intent);
}
6、访问文件:
//解决7.0隐私权限
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="${applicationId}.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths"/>
</provider>
7、provider_paths.xml:
<?xml version="1.0" encoding="utf-8"?>
<paths>
<external-path path="/app/download/" name="app_download" />
</paths>