2016-08-20 1 views
-1

Ich versuche, eine App zu erstellen, die mehrere Verknüpfung der gleichen App mit Benutzereingaben als Verknüpfungsname erstellen wird. aber jede Abkürzung wird andere spezifizierte Dinge tun. Dafür muss ich den Namen der Abkürzung kennen.Name der Android-Verknüpfung erhalten

+0

Mögliche Duplikate von [Verknüpfung für Android-Anwendung hinzufügen Zum Startbildschirm Auf Schaltfläche klicken] (http://StackOverflow.com/Questions/10343414/add-shortcut-for-android-application-to-home-screen-on-- Knopf-Klick) –

+0

Hallo @Ratul! Hast du einen Weg gefunden, dies zu tun? –

Antwort

0

Zuerst müssen Sie die INSTALL_SHORTCUT Erlaubnis

<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" /> 

Sie den Code unten verwenden können und Änderungen

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); 
} 

, dass eine Verknüpfung mit dem Launcher hinzufügen und eine benutzerdefinierte Aktivität von Ihrer App öffnen. Ich bin mir nicht sicher, was Sie wirklich tun wollen, da es unklar ist, wonach Sie fragen.

Verwandte Themen