1、 Android 9.0上QQ分享报错
原因
在 Android 6.0 中,我们取消了对 Apache HTTP 客户端的支持。
拥有最低 SDK 版本 23 或更低版本的应用需要 android:required=”false” 属性,
因为在 API 级别低于 24 的设备上,org.apache.http.legacy 库不可用。
解决方案
1、确保App对应build.gradle脚本配置中 compileSdkVersion值为28。
compileSdkVersion 28
......
defaultConfig {
applicationId "com.umeng.soexample"
minSdkVersion 18
targetSdkVersion 28
2、在App清单文件AndroidManifest.xml application项中配置useLibrary项。明确引用org.apache.http.legacy库。
......
<application android:label="@string/app_name"
android:icon="@drawable/umeng_share_solid_icon"
android:name=".App">
<uses-library android:name="org.apache.http.legacy" android:required="false"/>
<activity
......
3、sync gradle配置,clean工程,rebuild工程,重新安装App。已在运行Android 9.0的Google Pixel手机上实测,报错问题不再复现。
2、API 28导致的Canvas FLAG失效
原代码
int flags = Canvas.MATRIX_SAVE_FLAG |
Canvas.CLIP_SAVE_FLAG |
Canvas.HAS_ALPHA_LAYER_SAVE_FLAG |
Canvas.FULL_COLOR_LAYER_SAVE_FLAG |
Canvas.CLIP_TO_LAYER_SAVE_FLAG;
int sc = canvas.saveLayer(0, 0, getWidth(), getHeight(), null, flags);
更改为
int sc = canvas.saveLayer(0, 0, getWidth(), getHeight(), null, Canvas.ALL_SAVE_FLAG);
原因根据源码查看,在api28中已经全部改为:ALL_SAVE_FLAGS,其他已经无效:
/**
* Restore everything when restore() is called (standard save flags).
* <p class="note"><strong>Note:</strong> for performance reasons, it is
* strongly recommended to pass this - the complete set of flags - to any
* call to <code>saveLayer()</code> and <code>saveLayerAlpha()</code>
* variants.
*
* <p class="note"><strong>Note:</strong> all methods that accept this flag
* have flagless versions that are equivalent to passing this flag.
*/
public static final int ALL_SAVE_FLAG = 0x1F;
private static void checkValidSaveFlags(int saveFlags) {
if (sCompatiblityVersion >= Build.VERSION_CODES.P
&& saveFlags != ALL_SAVE_FLAG) {
throw new IllegalArgumentException(
"Invalid Layer Save Flag - only ALL_SAVE_FLAGS is allowed");
}
3、java.io.IOException: Cleartext HTTP traffic to dict.youdao.com not permitted
原因分析
从Android 6.0开始引入了对Https的推荐支持,与以往不同,Android P的系统上面默认所有Http的请求都被阻止了。
<application android:usesCleartextTraffic=true>
4、 notification没有显示
原因分析
如果targetsdkversion设定为26或以上,开始要求notification必须知道channel,具体查阅这里。
private void createNotificationChannel() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
CharSequence name = "";
String description = "";
int importance = NotificationManager.IMPORTANCE_DEFAULT;
NotificationChannel channel = new NotificationChannel(DOWNLOAD_CHANNEL_ID, name, importance);
channel.setDescription(description);
mNotificationManager.createNotificationChannel(channel);
}
}
5、无法通过“application/vnd.android.package-archive” action安装应用
原因分析
targetsdkversion大于25必须声明REQUEST_INSTALL_PACKAGES权限,见官方说明REQUEST_INSTALL_PACKAGES
在AndroidManifest中加入
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />