2016-08-20 102 views
-1

的名字,我想创建一个应用程序,它会创建一个用户输入快捷方式名称相同的应用程序的多个快捷方式。但每个快捷方式都会执行不同的指定操作。为此,我需要知道快捷方式的名称。越来越安卓快捷

+0

的可能重复的[添加快捷方式Android应用程序要在主屏幕上按一下按钮(http://stackoverflow.com/questions/10343414/add-shortcut-for-android-application-to-home-screen-on-按钮单击) –

+0

Hi @Ratul!你有没有找到一种方法来做到这一点? –

回答

0

首先,你需要的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); 
} 

这将快捷方式添加到启动程序,并从你的应用程序打开一个自定义的活动。我不确定你真的想做什么,因为它不清楚你要求什么。