越来越安卓快捷
答
首先,你需要的INSTALL_SHORTCUT许可
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
您可以使用下面的代码,并进行更改
EditText UserInput = (EditText)findViewById(R.id.userinput_text);
final String UserString = UserInput.getText().toString();
//Gets user input^
public void createIcon(){
Intent shortcutintent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
//So the shortcut doesn't get created multiple times
shortcutintent.putExtra("duplicate", false);
//UserString is the text from the user input to set the shortcut name
shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(UserString));
//set the icon picture
Parcelable icon = Intent.ShortcutIconResource.fromContext(getApplicationContext(), R.drawable.icon);
shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);
shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new
//Set the Activity that will be opened
Intent(getApplicationContext(), EnterActivity.class));
sendBroadcast(shortcutintent);
}
这将快捷方式添加到启动程序,并从你的应用程序打开一个自定义的活动。我不确定你真的想做什么,因为它不清楚你要求什么。
的可能重复的[添加快捷方式Android应用程序要在主屏幕上按一下按钮(http://stackoverflow.com/questions/10343414/add-shortcut-for-android-application-to-home-screen-on-按钮单击) –
Hi @Ratul!你有没有找到一种方法来做到这一点? –