为新版本中删除的那些变量和方法编写多个 Api 版本的代码

Writing code for multiple Api versions for those variables and methods which are deleted in newer versions

根据 these changes on Android 6.0 我无法编译我的代码,因为这一行 Browser.BOOKMARKS_URI 生成无法解析符号错误。

我试过这样写代码

if(Build.VERSION.SDK_INT < Build.VERSION_CODES.M){
            mCur = ctx.getContentResolver().query(Browser.BOOKMARKS_URI,
                    Browser.HISTORY_PROJECTION, null, null, "date DESC");
        }else{
            //TODO code for newer version
        }

我正在使用 api23 编译我的代码,但无法构建项目,我应该降低到 api22 还是有任何其他方法可以使用 api23 编译此代码。

从 Marshmallow 开始,您将无法实际使用书签。

来自Android issue tracker #2805

Global bookmarks are no longer available. They haven't really done anything for a long time anyway, since browsers these days generally keep their own internal bookmarks data rather than putting them in the global provider. Apps using the global provider should likewise switch to maintaining them internally.

但是,它们仍适用于 Android 的旧版本,但需要注意上述事项。要在继续针对 API 23 进行编译的同时支持旧版本的 Android,您需要对旧 URI 进行硬编码。

Looking at the Lollipop source,URI定义为

public static final Uri BOOKMARKS_URI = Uri.parse("content://browser/bookmarks");

在您自己的代码中定义它并像以前一样继续,但请确保您只在 API 22 及以下使用它。