调用需要API级别26(当前最小值为23):java.time.Instant#now [英] Call requires API level 26 (current min is 23): java.time.Instant#now

查看:83
本文介绍了调用需要API级别26(当前最小值为23):java.time.Instant#now的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在实现 Google的Directions API .我的应用程序支持 minSdkVersion 23 java.time.Instant 在这里不受支持.

I'm implementing Google's Directions API. My app supports minSdkVersion 23 and java.time.Instant is not supported here.

是否有解决方案,或者我应该只检查用户的版本并允许此功能(如果受支持)?

Is there a solution for this, or should i just check for user's version and allow this functionality if it's version is supported?

    DirectionsResult directionsResult = DirectionsApi.newRequest(geoApiContext)
            .mode(TravelMode.DRIVING)
            .origin(new com.google.maps.model.LatLng(mapFragment.getUserCoords().latitude, mapFragment.getUserCoords().longitude))
            .destination(tabHandlerCommunication.destinationBarCoords)
            .departureTime(Instant.now()) // <-- error here
            .await();

错误:

调用需要API级别26(当前最小值为23):java.time.Instant#now更少...(Ctrl + F1)检查信息:此检查将扫描所有Android API会在应用程序中调用并警告有关该调用的任何信息不适用于此应用程序定位的所有版本(根据清单中其最小的SDK属性).如果你确实想使用此API,并且不需要支持较旧的设备只需在build.gradle或AndroidManifest.xml中设置minSdkVersion文件.如果您的代码是故意访问较新的API,并且您确保(例如,有条件地执行)此代码将仅在受支持的平台上被调用,然后您便可以进行注释您的带有@TargetApi注释的类或方法,指定了要应用的本地最小SDK,例如@TargetApi(11),这样检查将11(而不是清单文件的最低SDK)视为所需的API级别.如果您是故意设置android:样式定义中的属性,请确保将其放在values-vNN文件夹,以避免在运行时遇到运行时冲突制造商添加了自定义属性的某些设备,id与更高版本的平台上的新ID冲突.同样,您可以在XML文件中使用tools:targetApi ="11"表示该元素只会在适当的情况下夸大其词.问题ID:NewApi

Call requires API level 26 (current min is 23): java.time.Instant#now less... (Ctrl+F1) Inspection info:This check scans through all the Android API calls in the application and warns about any calls that are not available on all versions targeted by this application (according to its minimum SDK attribute in the manifest). If you really want to use this API and don't need to support older devices just set the minSdkVersion in your build.gradle or AndroidManifest.xml files. If your code is deliberately accessing newer APIs, and you have ensured (e.g. with conditional execution) that this code will only ever be called on a supported platform, then you can annotate your class or method with the @TargetApi annotation specifying the local minimum SDK to apply, such as @TargetApi(11), such that this check considers 11 rather than your manifest file's minimum SDK as the required API level. If you are deliberately setting android: attributes in style definitions, make sure you place this in a values-vNN folder in order to avoid running into runtime conflicts on certain devices where manufacturers have added custom attributes whose ids conflict with the new ones on later platforms. Similarly, you can use tools:targetApi="11" in an XML file to indicate that the element will only be inflated in an adequate context. Issue id: NewApi

推荐答案

查看开发人员指南,结果发现,要么 String now

After reviewing the developer guide, it turned out that either String now,

以及常见的 int UNIX纪元时间戳是可接受的值:

as well as common int UNIX epoch timestamps, are being acceptable values:

出发时间-指定所需的出发时间.您可以将时间指定为自UTC 1970年1月1日午夜以来的秒数.另外,您可以指定一个 now 值,该值将出发时间设置为当前时间(更正为最接近的秒数).

departure_time — Specifies the desired time of departure. You can specify the time as an integer in seconds since midnight, January 1, 1970 UTC. Alternatively, you can specify a value of now, which sets the departure time to the current time (correct to the nearest second).

在检查源代码,有一种方便的方法:

When checking the source code of the Java client, there is a convenience method for that:

public DirectionsApiRequest departureTimeNow() {
    return param("departure_time", "now");
}

因此,为了向后兼容,可以绕过 java.time.Instant .

Therefore java.time.Instant can be circumvented, for the backwards compatibility.

我已经提交了 issue#559 ..分叉库似乎是设置其他时间戳的唯一方法.

I've filed issue #559... forking the library seems to be the only way to set other timestamps.

这篇关于调用需要API级别26(当前最小值为23):java.time.Instant#now的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆