tp官方网站下载app

你的位置:tp官方正版下载 > tp官方网站下载app >

tp钱包下载app官网正版 android 8.0 适配(总结)

发布日期:2025-05-05 06:50点击次数:165

android 8.0 对应的 sdk 版本  26

1. 通知栏

Android 8.0 引入了通知渠道,其允许您为要显示的每种通知类型创建用户可自定义的渠道。用户界面将通知渠道称之为通知类别。

针对 8.0 的应用,创建通知前需要创建渠道,创建通知时需要传入 channelId,否则通知将不会显示。示例代码如下:

2. 后台执行限制

如果针对 Android 8.0 的应用尝试在不允许其创建后台服务的情况下使用 startService() 函数,则该函数将引发一个 IllegalStateException。

我们无法得知系统如何判断是否允许应用创建后台服务,所以我们目前只能简单 try-catch startService(),保证应用不会 crash,tp官方网站下载app示例代码:

或者:

系统不允许后台应用创建后台服务, tp官方下载安装app Android 8.0 引入了一种全新的方法,即 Context.startForegroundService(),以在前台启动新服务.

将原来 startService方式启动服务修改为 startForegroundService启动服务

if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {     context.startForegroundService(checkIntent); } else {     context.startService(checkIntent); }

程序有通知的情况下:

https://www.imtokenqb.cn

在系统创建服务后,应用有五秒的时间来调用该服务的startForeground()方法以显示新服务的用户可见通知(如果应用在此时间限制内未调用 startForeground(),则系统将停止服务并声明此应用为 ANR),在服务的onCreate()方法中调用startForeground()即可。

@Override public void onCreate() {   super.onCreate();   if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {     createNotificationChannel();     Notification notification = new Notification.Builder(getApplicationContext(), channelID).build();     startForeground(1, notification);   } }

3. 允许安装未知来源应用

针对 8.0 的应用需要在 AndroidManifest.xml 中声明 REQUEST_INSTALL_PACKAGES 权限,否则将无法进行应用内升级。

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

4. 主题的 Activity 设置屏幕方向

将会抛出以下异常:

java.lang.IllegalStateException: Only fullscreen opaque activities can request orientation大概意思是:只有不透明的全屏Activity可以自主设置界面方向即使满足上述条件,该异常也并非一定会出现,为什么这么说,看下面两种表现:

12、属性动画组合AnimatorSet增加了setCurrentPlayTime和reverse方法,从而允许倒过来播放属性动画组合。 setCurrentPlayTime和reverse方法的调用方式示例如下:

隐式广播例外

Powered by tp官方正版下载 RSS地图 HTML地图

Copyright Powered by365站群 © 2013-2024