I have read developer guide of android developer official page and I have manage to create shortcut too. but I want to call my own activity (Explicit), instead of (Implicit) which is given in Android guide as an example. here is the URL for that https://developer.android.com/preview/shortcuts.html
I have made my code like this
ShortcutManager shortcutManager = getSystemService(ShortcutManager.class);
ShortcutInfo shortcut = new ShortcutInfo.Builder(this,"id1")
.setShortLabel("Web site")
.setLongLabel("Open the web site")
.setIntent(new Intent(this,Shortcut.class))
.build();
when I run the app I get this error message
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.murtaza.style2, PID: 4187
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.murtaza.style2/com.murtaza.style2.MainActivity}: java.lang.NullPointerException: intent's action must be set
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2665)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Caused by: java.lang.NullPointerException: intent's action must be set
at com.android.internal.util.Preconditions.checkNotNull(Preconditions.java:111)
at android.content.pm.ShortcutInfo$Builder.setIntents(ShortcutInfo.java:987)
at android.content.pm.ShortcutInfo$Builder.setIntent(ShortcutInfo.java:968)
at com.murtaza.style2.MainActivity.onCreate(MainActivity.java:74)
at android.app.Activity.performCreate(Activity.java:6679)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2618)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Application terminated.
How can I call an other activity by pressing that shortcut instead of calling any other app?
It's not 3 year old concept of putting shortcuts on home-screen its just announced with android 7.1. I want to know how to call activity by pressing that shortcut.