Android9 新特性

1.Wi-Fi RTT 进行室内定位

室内WIFI定位 Android P增加了对RTT Wi-Fi协议的支持,以此作为室内定位的基础。
在支持硬件支持的Android P设备上,开启定位并且打开WIFI扫描后就可以使用该功能进行定位。应用可以测量与附近支持RTT的Wi-Fi接入点(AP)的距离。设备必须启用位置并启用Wi-Fi扫描(在设置>位置下)。使用这个功能不会连接到WIFI,而且为了保持隐私,只有手机能确定AP到设备的距离,反之则不能。 如果设备测量到3个或更多AP的距离,则可以使用多点定位算法来估算最适合这些测量值的设备位置。其结果通常可以精确到1至2米范围

RangingRequest.Builder builder = new RangingRequest.Builder(); 
builder.addAccessPoint(); 
builder.addWifiAwarePeer(); 
wifiRttManager.startRanging(builder.build(), () -> {...}, new RangingResultCallback{...});
2.刘海屏支持

可以使用类似windowInsets.getDisplayCutout()来获取一些你想要的信息。

getRootWindowInsets().getDisplayCutout().getSafeInsetBottom(); 
getRootWindowInsets().getDisplayCutout().getSafeInsetLeft(); 
getRootWindowInsets().getDisplayCutout().getSafeInsetRight(); 
getRootWindowInsets().getDisplayCutout().getSafeInsetTop(); 

WindowManager windowManager = (WindowManager) getApplicationContext().getSystemService(Context.WINDOW_SERVICE); 
WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams(); 
layoutParams.layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS;
layoutParams.layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_DEFAULT; 
layoutParams.layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_NEVER;

3.通知栏的体验优化

从安卓7.0 开始优化 在P版本可以使用setData()来显示图像

//新的聊天对象 Notification.Person p = new Notification.Person();
//在MessagingStyle中用Person代替了以往的CharSequence
Notification.MessagingStyle messageStyle = new Notification.MessagingStyle(p); 
Notification.MessagingStyle.Message message = new Notification.MessagingStyle.Message("aaa", 100, p); 
//可以显示图像了
message.setData(); 
messageStyle.addMessage(message); 
builder.setStyle(messageStyle); 
Notification notification = builder.build();

4.新的图片解码

Android P新增了ImageDecoder类,为解码图像提供了一种更优的方法。由此可以用ImageDecoder来替换BitmapFactory和BitmapFactory.Options。

String filePath = "/storage/emulated/0/download/img.png";
File file = new File(filePath);
ImageDecoder.Source source = ImageDecoder.createSource(file);;
ImageDecoder.decodeBitmap(source);
ImageDecoder.decodeDrawable(source, (imageDecoder, imageInfo, source1) -> {
    imageDecoder.setCrop();
    imageDecoder.setResize();
});
BitmapFactory.decodeFile(filePath);

5.新的动画库:

Android P引入了一个新的AnimatedImageDrawable类来绘制和显示GIF和WebP动画图像。 AnimatedImageDrawable与AnimatedVectorDrawable类似,因为AnimatedImageDrawable动画也是基于RenderThread工作的。 RenderThread本身在内部使用工作线程进行解码,因此解码不会干扰RenderThread。 这种实现允许您的应用拥有动画图像,而无需管理其更新或干扰应用的UI线程。

可使用 ImageDecoder 的实例对 AnimatedImageDrawable 进行解码。 以下代码段演示如何使用 ImageDecoder 来解码 AnimatedImageDrawable:

    Drawable decodedAnimation = ImageDecoder.decodeDrawable(
        ImageDecoder.createSource(getResources(), R.drawable.my_drawable));

    if (decodedAnimation instanceof AnimatedImageDrawable) {
        // Prior to start(), the first frame is displayed.
        ((AnimatedImageDrawable) decodedAnimation).start();
    }
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值