我做了一个聊天活动的快捷方式,并且工作正常。我使用的功能如下:
private void addShortcut() {
// Adding shortcut for MainActivity
// on Home screen
Intent shortcutIntent = new Intent(GroupChat.this, SignUp.class);
shortcutIntent.setAction(Intent.ACTION_MAIN);
Intent addIntent = new Intent();
addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, groupName);
addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
Intent.ShortcutIconResource.fromContext(GroupChat.this,
R.drawable.contact));
addIntent.putExtra("duplicate", false);
addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
GroupChat.this.sendBroadcast(addIntent);
}
问题是,当用户单击聊天活动的快捷方式时,我需要知道快捷方式的名称,以便可以加载合适的聊天活动。我怎样才能做到这一点?
先谢谢了!:)
将快捷方式名称添加到Intent
将用于启动您的应用程序的名称:
Intent shortcutIntent = new Intent(GroupChat.this, SignUp.class);
shortcutIntent.setAction(Intent.ACTION_MAIN);
// Add the shortcut name as an Extra so SignUp activity can get it
shortcutIntent.putExtra("shortcutname", groupName);
在SignUp.onCreate()
这样做是为了得到它:
String shortcutname = getIntent().getStringExtra("shortcutname");
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句