美文网首页
targetSdkVersion升级到28问题

targetSdkVersion升级到28问题

作者: 主音King | 来源:发表于2019-02-21 14:41 被阅读0次

    错误1: java.io.IOException: Cleartext HTTP traffic to 包名 not permitted
    原因分析:
    从Android 6.0开始引入了对Https的推荐支持,与以往不同,Android P的系统上面默认所有Http的请求都被阻止了。

    <application android:usesCleartextTraffic=["true" | "false"]>
    

    原本这个属性的默认值从true改变为false
    解决办法:
    AnroidManifest.xml中的application显示设置

    <application android:usesCleartextTraffic="true">
    

    更为根本的解决办法是修改应用程序中Http的请求为Https,当然这也需要服务端的支持。

    错误2: 在8.0之后前台服务使用startForegroundService()启动,需要权限

    <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
    

    错误3:android 8.0 报错StartForeground Bad Notification Error 解决方法
    在android8.0后 需要给notification设置一个channelid

    public final static String channelName="cn.george.app";
    
    mNotificationManager.createNotificationChannel(
    new NotificationChannel(channelName,
    "Channel One",
    NotificationManager.IMPORTANCE_HIGH));
    
    NotificationCompat.Builder builder = 
    new NotificationCompat.Builder(this,channelName)
                    .setContent(remoteViews)
                    .setSmallIcon(R.mipmap.pic);
    

    相关文章

      网友评论

          本文标题:targetSdkVersion升级到28问题

          本文链接:https://www.haomeiwen.com/subject/vobryqtx.html