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

冷暖自知 提交于 2019-12-23 07:29:07

问题


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

回答1:


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

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


来源:https://stackoverflow.com/questions/40459174/update-android-sdk-install-latest-platform-to-implement-new-apis-such-as-shor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!