【问题标题】:getting name of android shortcut获取android快捷方式的名称
【发布时间】:2016-08-20 21:04:58
【问题描述】:

我正在尝试创建一个应用程序,该应用程序将使用用户输入作为快捷方式名称创建同一应用程序的多个快捷方式。但是每个快捷方式都会做不同的指定事情。为此,我需要知道快捷方式的名称。有什么可能的方法吗?

【问题讨论】:

标签: android shortcut


【解决方案1】:

首先您需要 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);
}

这将为启动器添加一个快捷方式并从您的应用中打开一个自定义活动。我不确定您真正想要做什么,因为不清楚您要的是什么。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-09-06
    • 2016-07-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-14
    • 1970-01-01
    相关资源
    最近更新 更多