Develop
2016.11.15 14:38
[android] How can I place app icon on launcher home screen?
조회 수 1393 댓글 0
홈화면에 아이콘 추가하기. ㅋㄷ
AndroidManifest.xml 파일에 권한 추가.
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
실행화면에 코드 추가.
Intent shortcutIntent = new Intent(); shortcutIntent.setClassName("packageName", "className"); //shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); //shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); Intent addIntent = new Intent(); addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent); addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "shortcut_name"); addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(context, R.drawable.icon)); //intent.putExtra("duplicate", false); addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT"); context.sendBroadcast(addIntent);
## 좀 더 정리된 버전은..
Permissions:
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" /> <uses-permission android:name="com.android.launcher.permission.UNINSTALL_SHORTCUT" />
BroadcastReceiver:
<receiver android:name="YOUR.PACKAGE.PackageReplacedReceiver"> <intent-filter> <action android:name="android.intent.action.PACKAGE_REPLACED" /> <data android:scheme="package" android:path="YOUR.PACKAGE" /> </intent-filter> </receiver>
Functions:
private void addShortcut() { //Adding shortcut for MainActivity //on Home screen Intent shortcutIntent = new Intent(getApplicationContext(), SplashActivity.class); shortcutIntent.setAction(Intent.ACTION_MAIN); Intent addIntent = new Intent(); addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent); addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.app_name)); addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(getApplicationContext(), R.mipmap.ic_launcher)); addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT"); addIntent.putExtra("duplicate", false); //may it's already there so don't duplicate getApplicationContext().sendBroadcast(addIntent); } public void removeShhortcut(){ Intent shortcutIntent = new Intent(getApplicationContext(), SplashActivity.class); shortcutIntent.setAction(Intent.ACTION_MAIN); Intent addIntent = new Intent(); addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent); addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.app_name)); addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(getApplicationContext(), R.mipmap.ic_launcher)); addIntent.setAction("com.android.launcher.action.UNINSTALL_SHORTCUT"); addIntent.putExtra("duplicate", false); //may it's already there so don't duplicate getApplicationContext().sendBroadcast(addIntent); }
TAG •
- Shortcut Icon,
- Android,
- 안드로이드,
- 바탕화면,
- 단축키,
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
393 | Develop |
[c] 프로그램 코드(c/c++)를 html 파일로 변환
![]() |
hooni | 2013.04.23 | 7684 |
392 | Develop |
[c] 전위 표기법으로 연산 예제..
![]() |
hooni | 2013.04.23 | 9310 |
391 | PPT |
[doc] 정보보호학술대회 논문지 ㅋㅋ
![]() |
hooni | 2013.04.23 | 12190 |
390 | Develop | [ajax] 샘플 코드와 한글처리에 대한 간단한 설명 | hooni | 2013.04.23 | 6867 |
389 | Etc | GSM에서 음성이 실리는 과정 요약.. | hooni | 2013.04.23 | 17572 |
388 | Develop | [js] 폼(form) 전송시 중복 클릭 방지 간단한 구문 | hooni | 2013.04.23 | 9324 |
387 | Develop | [js] 사진첩에 쓸 내용 - 마우스 오버로 바꾸기 | hooni | 2013.04.23 | 6353 |
386 | Database | [sql] 간단한 통계 서브쿼리 예제.. | hooni | 2013.04.23 | 15142 |
385 | Develop | [java] Sieve of Eratosthenes (에라토스테네스의 체) | hooni | 2013.04.23 | 9345 |
384 | Develop |
[c] 유닉스 프로그램에서 인수처리 해주는 getopt() 함수
![]() |
hooni | 2013.04.23 | 8081 |
383 | Develop |
[c] pcapdump 파일 분석 하는 프로그램.. ㅋㅋ
![]() |
hooni | 2013.04.23 | 6907 |
382 | Develop |
[php] 무조건 다운로드 받도록 header 세팅
![]() |
hooni | 2013.04.23 | 7409 |