1
這工作得很好,但現在它顯然沒有。這裏是我的代碼:Android - 應用程序使應用程序的名稱,而不是Intent.EXTRA_SHORTCUT_NAME的快捷方式
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);
}
我吐司顯示正確的快捷方式名稱,但是當我把它添加到主屏幕這是我的應用程序的名字。
感謝,
DylanG
這裏的解決方案: http://stackoverflow.com/questions/6988511/how-to-add-apps-快捷方式到到戶屏 –