java处理更高版本Android中引入的类
假设我有一个具有许多功能的应用程序,其中一个是使用安卓.bluetooth.BluetoothGatt
仅在Android API 18之后可用。但我的应用程序也应该适用于较旧的API版本
我能一直写作吗
import 安卓.bluetooth.BluetoothGatt;
public class ActivityMain extends Activity {
BluetoothGatt gatt = null;
...
}
在API版本早于18的手机上使用此活动时不会出现问题,也不会遇到任何问题,只要我的代码在实践中从未达到使用某些常量或方法不可用的指令?例如,在ActivityMain
的方法中,我会写
BluetoothDevice device = ...
if (Build.VERSION.SDK_INT >= 18)
gatt = device.connectGatt(...)
为了确保gatt
在BluetoothGatt
还不受支持的情况下null
保持null
如果我的方法不起作用,我能做些什么
共 (0) 个答案