티스토리 뷰

private void addShortcut(Context context) {

Intent shortcutIntent = new Intent();

shortcutIntent.setAction(Intent.ACTION_MAIN);

shortcutIntent.addCategory(Intent.CATEGORY_LAUNCHER);

shortcutIntent.setClassName(context, getClass().getName());

shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_CLEAR_TOP);

 

Parcelable iconResource = Intent.ShortcutIconResource.fromContext( this,  R.drawable.ic_launcher);

 

Intent intent = new Intent();

intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);

intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getResources().getString(R.string.app_name));

intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,iconResource);

intent.putExtra("duplicate", false);

intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");       

sendBroadcast(intent);  

 } 


그리고 퍼미션 추가

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



필요한곳에 위 메서드를 만들고 호출해주면 된다.

본인은 로딩화면에서 처리해주었다.


실행할때마다 바로가기를 만드는데 최초 1회만 실행시켜주는 처리를 해주어야 할것같다.

프리퍼런스나 데이터값 저장을 해야할것같다.

댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함