This is an example of a code for creating a direct shortcut that calls a specific number and which works on Android M and below.
public void installShortcutGetId(){
Intent intent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME,"MyCallShortcut");
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(Intent.ACTION_CALL, Uri.parse("tel:77777777")));
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(context, android.R.drawable.sym_def_app_icon));
context.sendBroadcast(intent);
}
The same code doesn't work anymore on Android N, I can see in the logcat the following:
/com.android.launcher3 E/InstallShortcutReceiver: Ignoring malicious intent tel:77777777#Intent;action=android.intent.action.CALL;end
If I change ACTION_CALL to ACTION_DIAL, it works on Android N but that's not what I am looking for. I am looking for a way to make a direct call through the shortcut.
In terms of permissions, I have these 2 included and CALL_PHONE requested at run-time.
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
<uses-permission android:name="android.permission.CALL_PHONE" />
Just because your app has the CALL_PHONE permission doesn't mean the launcher has that permission: that's why your shortcut cannot be created.
You could instead create a shortcut to an empty activity of your own and start the
ACTION_CALL
Intent from that activity.