这里我正在为Android nougat App快捷方式中引入的android快捷键进行演示。
我使用了下面的代码来创建应用快捷方式
ShortcutManager shortcutManager;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
shortcutManager = getSystemService(ShortcutManager.class);
ShortcutInfo shortcut;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N_MR1) {
shortcut = new ShortcutInfo.Builder(this, "second_shortcut")
.setShortLabel(getString(R.string.str_shortcut_two))
.setLongLabel(getString(R.string.str_shortcut_two_desc))
.setIcon(Icon.createWithResource(this, R.mipmap.ic_launcher))
.setIntent(new Intent(Intent.ACTION_VIEW,
Uri.parse("https://www.google.co.in")))
.build();
shortcutManager.setDynamicShortcuts(Arrays.asList(shortcut));
}
}
但是这里我得到的是编译时错误 cannot resolve symbol ShortcutManager
。
这是我的build.gradle
文件
apply plugin: 'com.android.application'
android {
compileSdkVersion 24
buildToolsVersion "24.0.3"
defaultConfig {
...
minSdkVersion 9
targetSdkVersion 24
...
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:24.2.1'
}
发布于 2016-11-07 06:49:19
您需要更新您的dependency
,因为ShortcutManager
是在API 25中添加的,因此您应该更新/安装API 25的以下组件
并对您的build-gradle file
进行必要的更改,如图像中所示:
将下列项目的值更新为25
遵循链接以查看 API 25中提供的特性更新(v7.1)
最后,通过使用ShortcutManager
成功构建,它将看起来像这样
还有一些其他重要的包您可能也想更新。
https://stackoverflow.com/questions/40459174
复制相似问题