Android - приложение делает ярлык с именем приложения, а не Intent.EXTRA_SHORTCUT_NAME - PullRequest
1 голос
/ 18 июля 2011

Раньше это работало нормально, но теперь, очевидно, нет. Вот мой код:

if (options[item].equals("Add to Home Screen")) {
    Intent shortcutIntent = new Intent();
    shortcutIntent.setClassName("net.dylang.android.system_sounds_pro", "net.dylang.android.system_sounds_pro.SystemSounds");
    shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    shortcutIntent.putExtra("profileName", SystemSounds.prop.getProperty(((String) button.getText()).replaceAll(" ", "-")));
    shortcutIntent.putExtra("profileText", button.getText());

    if (SystemSounds.prop.getProperty("vibrated-ringers").contains(((String) button.getText()).replaceAll(" ", "-"))) 
        shortcutIntent.putExtra("vibratedringsi", "true");
    else
        shortcutIntent.putExtra("vibratedringsi", "false");

    if (SystemSounds.prop.getProperty("vibrated-notifications").contains(((String) button.getText()).replaceAll(" ", "-"))) 
        shortcutIntent.putExtra("vibratednotsi", "true");
    else
        shortcutIntent.putExtra("vibratednotsi", "false");

    Intent addIntent = new Intent();

    Toast.makeText(getApplicationContext(), shortcutIntent.getStringExtra("profileText"), 0).show();

    addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, shortcutIntent.getStringExtra("profileText"));                           
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(ProfilesPage.this, R.drawable.icon));
    addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");

    ProfilesPage.this.sendBroadcast(addIntent);
}

My Toast показывает правильное имя ярлыка, но когда я добавляю его на главный экран, это имя моего приложения.

Спасибо

DylanG

1 Ответ

0 голосов
/ 07 октября 2013

попробуйте

    public void createShortCut(){
    // a Intent to create a shortCut
    Intent shortcutintent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
    //repeat to create is forbidden
    shortcutintent.putExtra("duplicate", false);
    //set the name of shortCut
    shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "SmS ");

    //set icon
    Parcelable icon = Intent.ShortcutIconResource.fromContext(getApplicationContext(), R.drawable.ic_launcher);
    shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);
    //set the application to lunch when you click the icon
    shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(getApplicationContext() , MainActivity.class));
    //sendBroadcast,done
    sendBroadcast(shortcutintent);
}
...