public static void addShortcut(Context context)
{
if(!pref.getBoolean("addshotcut",false))
{
editor.putBoolean("addshotcut", true);
editor.commit();
Intent shortcutIntent = new Intent(Intent.ACTION_MAIN);
shortcutIntent.addCategory(Intent.CATEGORY_LAUNCHER);
shortcutIntent.setClassName(context, context.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,
context.getResources().getString(R.string.app_name));
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
Intent.ShortcutIconResource.fromContext(context,
R.drawable.ic_launcher));
intent.putExtra("duplicate", false);
intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
context.sendBroadcast(intent);
}
}
Manifest에
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
추가
'안드로이드' 카테고리의 다른 글
트리리스트 3단계 이상 내려가는 소스 (0) | 2015.05.22 |
---|---|
Strings 에서 parameter 넣기 (0) | 2015.05.11 |
파일 탐색기 (0) | 2014.10.02 |
어플리케이션 중복 실행 방지 (0) | 2014.08.19 |
안드로이드 네이버 지도 API 분석중 (0) | 2013.08.05 |