2011년 9월 7일 수요일

어플리케이션 바로가기 아이콘 등록 및 해제

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

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



public void onClick(View v) {
switch(v.getId()){
case R.id.button1:
Intent shortcutIntent = new Intent(Intent.ACTION_MAIN);
shortcutIntent.addCategory(Intent.CATEGORY_LAUNCHER);
shortcutIntent.setClassName(mContext, getClass().getName());
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);

Intent intent = new Intent();
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, shortCutName);
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(mContext, R.drawable.icon));
intent.putExtra("duplicate", false);
intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
sendBroadcast(intent);

Toast.makeText(mContext, "Install shortcut", Toast.LENGTH_SHORT).show();
finish();
break;
case R.id.button2:
Intent shortcutUnIntent = new Intent(Intent.ACTION_MAIN);
shortcutUnIntent.addCategory(Intent.CATEGORY_LAUNCHER);
shortcutUnIntent.setClassName(mContext, getClass().getName());
shortcutUnIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);

Intent i = new Intent();
i.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutUnIntent);
i.putExtra(Intent.EXTRA_SHORTCUT_NAME, shortCutName);
i.putExtra("duplicate", false);
i.setAction("com.android.launcher.action.UNINSTALL_SHORTCUT");
sendBroadcast(i);

Toast.makeText(mContext, "UnInstall shortcut", Toast.LENGTH_SHORT).show();
finish();
break;
}
}

댓글 없음:

댓글 쓰기