Here i am performing demo for Android Shortcuts introduces in android nougat App Shortcuts
I have used following code to create app shortcut
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));
}
}
But here i am getting compile time error cannot resolve symbol ShortcutManager
.
Here is my build.gradle
file
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'
}
You need to update your
dependency
becauseShortcutManager
is added in API 25 as mentioned here so you should update/install the below components for API 25and make the necessary changes in your
build-gradle file
as show in the image too :Update your following project’s values to 25
Follow the link to see the features updates provided in API 25 (v7.1)
And eventually it will look this, with succesful build using
ShortcutManager
There are some other crucial packages you might want to update too