1
可能重复:
Android create shortcuts on the home screen创建Android应用程序的主屏幕上的快捷方式
我想尽快创建我的主屏幕上的Android应用程序的快捷方式为我的应用程序是安装在Android设备上。我该怎么做呢..?
可能重复:
Android create shortcuts on the home screen创建Android应用程序的主屏幕上的快捷方式
我想尽快创建我的主屏幕上的Android应用程序的快捷方式为我的应用程序是安装在Android设备上。我该怎么做呢..?
由@Kailash答:
你可以用下面的代码,它的工作对我来说:
Intent shortcutIntent = new Intent();
shortcutIntent.setClassName("WRITE YOUR PACKAGE NAME", "WRITE HERE YOUR CLASS NAME");
Intent addIntent = new Intent();
addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "WRITE HERE YOUR 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);
您的AndroidManaifest.xml
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
使用以下
许可希望它有助于。
@ Ram,我想在应用程序安装在设备上时立即创建一个快捷方式。我想在第一次打开我的应用程序之前创建它。我不想在点击按钮上创建它。 – adi