我知道它没有记录,也不适用于所有设备,但我看到越来越多的应用程序在安装后将其快捷方式放在主屏幕上.发现一堆代码块如何做到但对我来说它们并不适合.这就是我现在所得到的.
需要清单中的权限.
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
Run Code Online (Sandbox Code Playgroud)创建应该调用的活动的Intent.Ex(来自cgeek):
Intent shortcutIntent = new Intent();
shortcutIntent.setClassName("com.example.androidapp", "SampleIntent");
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
Run Code Online (Sandbox Code Playgroud)创建快捷方式
Intent addIntent = new Intent();
addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "Shortcut Name");
addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(context, R.drawable.icon));
addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
context.sendBroadcast(addIntent);
Run Code Online (Sandbox Code Playgroud)我的问题是:在安装.apk后,这段代码应该去哪里添加快捷方式?我在启动器活动中尝试了此代码,每次应用启动时都会创建损坏的(另一个故事)快捷方式.
如您所知,当正常安装应用程序时,会在启动器菜单屏幕上创建图标.我想要做的是在安装过程中在用户主屏幕上创建图标.(不按图标5秒钟.)
我从另一个来源听到这个只是添加
<category android:value="android.intent.category.HOME" />
Run Code Online (Sandbox Code Playgroud)
到AndroidManifest.xml文件,但它没有用.
还有其他办法吗?