Ravi Rupareliya Ravi Rupareliya - 17 days ago 8
Android Question

Update android SDK : install latest platform to implement new APIs such as "ShortcutManager"

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'
}

Answer

You need to update your dependency because ShortcutManager is added in API 25 as mentioned here so you should update/install the below components for API 25

  • Build-Tools
  • Install API 25 platform
  • Android Support Respository
  • SDK Tools
  • SDK Platform Tools

and make the necessary changes in your build-gradle file as show in the image too :

Update your following project’s values to 25

  • compileSdkVersion
  • buildToolsVersion

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

enter image description here

There are some other crucial packages you might want to update too

  • USB drivers : For USB device debugging
  • Play service : For latest APIs added in Google maps,google+ etc
  • System images : To practice with latest AVD devices
  • Android Support Repository : Support libraries for android devices,TV etc
  • Google Repository : For features Firebase, Google Maps, Games achievements and leaderboards