AndroidP版本第7季targetSdkVersion政策

        1. 2018年8月 新发布应用-必现为26或更高
        2. 2018年11月 升级现有应用-必须为26或者更高
        3. 2019年之后 新发布或升级应用-必须为一年内发布的Android版本
    1. 国内TargetSdkVersion政策

谷歌要求P版本上面应用设置的targetSdkVersion需要>=17,否则会弹出警告对话框提示用户,并且谷歌有明确的CDD要求,该提示无法去掉。

    1. TargetSdkVersion升级指南

https://developer.android.google.cn/distribute/best-practices/develop/target-sdk

  1. 其他对所有targetSdkVersion生效的变更

参考文档:https://developer.android.com/about/versions/pie/android-9.0-changes-all

    1. FLAG_ACTIVITY_NEW_TASK被强制要求

在P版本,如果不在Intent添加FLAG_ACTIVITY_NEW_TASK,将无法通过非Activity的Context启动一个Activity,并且会抛异常。

比如在Service中启动Activity,如果Intent不添加FLAG_ACTIVITY_NEW_TASK,就会抛异常:

@Override
    public void onCreate() {
        Log.v(TAG, "ServiceDemo onCreate");
        super.onCreate();
        Intent intent = new Intent(this, Main2Activity.class);
//        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);
    }

    1. Crypto provider在P版本去掉了

从P版本开始,Crypto JCA provider被去掉了,调用SecureRandom.getInstance(“SHA1PRNG”, “Crypto”) 将会报NoSuchProviderException。

    1. 限制访问 Wi-Fi 位置和连接信息
        1. Wi-Fi位置信息

在 Android 9 中,应用进行 Wi-Fi 扫描的权限要求比之前的版本更严格。 除了需要下面权限

还需要用户开启位置开关

        1. 获取Wifi的SSID 和 BSSID 值

类似的限制也适用于 getConnectionInfo() 函数,该函数返回描述当前 Wi-Fi 连接的 WifiInfo 对象。 如果调用应用具有以下权限,则只能使用该对象的函数来检索 SSID 和 BSSID 值,也是通过Wifi位置信息一样,增加了位置开关必须打开的要求

        1. 兼容性影响

影响应用通过wifi获取位置信息以及获取wifi的SSID 和 BSSID 值

        1. 适配指导
  • 通过wifi获取位置信息和wifi的SSID 和 BSSID之前,需要先判断一下位置开关是否打开,如果位置开关关闭,需要提示用户主动开启

public static boolean isLocationEnabled(Context context){
    return Settings.Secure.getInt(context.getContentResolver(), Settings.Secure.LOCATION_MODE,
            Settings.Secure.LOCATION_MODE_OFF) != Settings.Secure.LOCATION_MODE_OFF;
}

  • 如果定位开关未打开,跳转到位置开关设置页面:

Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivity(intent);

猜你喜欢

转载自blog.csdn.net/qq_33209777/article/details/88165814