앱 설치 시 최초에만 홈 스크린에 바로가기 아이콘이 생기게 하려는 것이 목적입니다~
문제가 없습니다 일단.
Intent shortcutIntent = new Intent(Intent.ACTION_MAIN);
shortcutIntent.addCategory(Intent.CATEGORY_LAUNCHER);
shortcutIntent.setClassName(this, this.getClass().getName());
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
Intent intent = new Intent();
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.app_name));
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(this, R.drawable.launcher_icon));
intent.putExtra("duplicate", false);
intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
sendBroadcast(intent);
를 onCreate() 에서 호출합니다.
그럼 앱이 실행될 때 마다 위의 코드들을 거쳐 홈스크린에 바로가기를 생성한다는 토스트를 시스템이 띄우고 바로가기를 만들더군요
여기서 질문입니다.
1. intent.putExtra("duplicate", false);
를 해주니까 이미 생성이 돼있으면 생성 돼있다고 토스트를 띄워주던데 이 코드는 모든 api level 에서 유효한 코드인가요?
2. 저 코드를 사용하니까 매번 앱 실행마다 바로가기가 이미 존재합니다 라는 시스템에서 띄워주는 토스트가 뜨는게 맘에 안듭니다.
putExtra("duplicate", false) 를 이용하는 방법 말고 다른 방법으로 이미 바탕화면에 깔려있는지 확인 하는 방법은 없을까요?