android适配9.0布局,关于该项目运行在Android 9.0 系统上的适配问题。

需要适配 网络请求。

在manifest中Application中添加 android:networkSecurityConfig="@xml/network_security_config" 属性,其中network_security_config是 xml中的文件,代码如下:

关于运行的时候需要添加前台的权限

在manifest 添加

运行的时候报如下错误:

19-02-21 15:56:30.431 12154-12154/me.wcy.music E/AndroidRuntime: FATAL EXCEPTION: main

Process: me.wcy.music, PID: 12154

android.app.RemoteServiceException: Bad notification for startForeground: java.lang.RuntimeException: invalid channel for service notification: Notification(channel=273 pri=0 contentView=me.wcy.music/0x7f0c0046 vibrate=null sound=null defaults=0x0 flags=0x40 color=0x00000000 vis=PRIVATE)

at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2050)

at android.os.Handler.dispatchMessage(Handler.java:109)

at android.os.Looper.loop(Looper.java:207)

at android.app.ActivityThread.main(ActivityThread.java:7470)

at java.lang.reflect.Method.invoke(Native Method)

at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:524)

at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:958)

解决方法是: 在Notifier 修改对应方法的代码如下:

private static final String CHANNELID = "me.wcy.music.application.1"; private static NotificationChannel mChannel = null; //通知栏 private static NotificationCompat.Builder builder; //通知和自定义通知 private Notification buildNotification(Context context, Music music, boolean isPlaying) { Intent intent = new Intent(context, MusicActivity.class); intent.putExtra(Extras.EXTRA_NOTIFICATION, true); intent.setAction(Intent.ACTION_VIEW); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); //修改这里的代码------------------------------------------------------------ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { builder = new NotificationCompat.Builder(context, CHANNELID); mChannel = notificationManager.getNotificationChannel(CHANNELID); if (mChannel == null) { mChannel = new NotificationChannel(CHANNELID, "音频播放", NotificationManager.IMPORTANCE_LOW); } mChannel.enableLights(false);//是否在桌面icon右上角展示小红点 mChannel.setSound(null, null); //设置通知声音 mChannel.setShowBadge(false);//是否在久按桌面图标时显示此渠道的通知 mChannel.enableVibration(false); if (notificationManager != null) { notificationManager.createNotificationChannel(mChannel); } } else { builder = new NotificationCompat.Builder(context); } builder.setContentIntent(pendingIntent) .setSmallIcon(R.drawable.ic_notification) .setCustomContentView(getRemoteViews(context, music, isPlaying)); builder.setOngoing(true); //--------------------------------------------------------------------------------------------------- return builder.build();

我运行的环境是 Android studio 3.3.1 希望对后面的小伙伴有用。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值