2012-04-27 61 views
1

如何为主活动创建应用程序图标?创建应用程序图标

我想创建一个快捷方式自定义主屏幕页面上我的应用程序图标。

我希望把它应用主屏幕上的应用程序安装后。

我该怎么做?

+0

欢迎SO!请在此搜索现有问题,因为同一问题已存在许多QA。 – 2012-04-27 07:49:50

回答

0

创建你的图标,把它放在绘制文件夹,然后在你的清单...

<application 
    android:icon="@drawable/your_icon" 
    android:label="@string/app_name" > 
+1

-1仔细阅读问题。他想在主屏幕上创建应用程序快捷方式。 – 2012-04-27 07:49:11

+0

嗯我不知道为什么downvote?基本上这似乎是答案 – 2012-04-27 07:49:22

+0

@PareshMayani也许我误解了这个问题,我的编辑改变了它? – 2012-04-27 07:50:48

2

添加快捷方式

private void addShortcut(){ 
Intent shortcutIntent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT"); 

// Shortcut name 
shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.app_name)); 
shortcutIntent.putExtra("duplicate", false); 

ComponentName comp = new ComponentName(this.getPackageName(), "."+this.getLocalClassName()); 
shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(Intent.ACTION_MAIN).setComponent(comp)); 

// Shortcut icon 
ShortcutIconResource iconRes = Intent.ShortcutIconResource.fromContext(this, R.drawable.icon); 
shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconRes); 

sendBroadcast(shortcutIntent); 
} 

方法removeing快捷

方法
private void delShortcut(){ 
Intent shortcut = new Intent("com.android.launcher.action.UNINSTALL_SHORTCUT"); 

// Shortcut adı 
shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.app_name)); 

String appClass = this.getPackageName() + "." +this.getLocalClassName(); 
ComponentName comp = new ComponentName(this.getPackageName(), appClass); 
shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(Intent.ACTION_MAIN).setComponent(comp)); 

sendBroadcast(shortcut); 
} 

上的OnCreate

public void onCreate(Bundle savedInstanceState) { 
super.onCreate(savedInstanceState); 
setContentView(R.layout.main); 
delShortcut(); 
addShortcut(); 

权限调用方法添加快捷方式

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