Develop
2016.11.15 14:38
[android] How can I place app icon on launcher home screen?
조회 수 1403 댓글 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,
- 안드로이드,
- 바탕화면,
- 단축키,
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
141 | Develop |
[c++] mfc 윈도우에서 ODBC 사용하여 MDB파일 읽기.. ㅋㅋ
![]() |
hooni | 2013.04.23 | 9141 |
140 | Develop | [c++] MFC 모든 헤더와 라이브러리 설명 | [교류]Programming | hooni | 2013.04.23 | 7457 |
139 | Develop |
[c++] mfc 기반 멀티수납(wall)시스템 소스와 실행파일
![]() |
hooni | 2013.04.23 | 7075 |
138 | Develop | [c++] mfc 기반 레지스트리(registry) 컨트롤 예제 코드 2 | hooni | 2013.04.23 | 15368 |
137 | Develop | [c++] mfc 간단한 파일 입출력 예제 | hooni | 2013.04.23 | 13550 |
136 | Develop |
[c++] MD5 구현 소스.. 퍼움..
![]() |
hooni | 2013.04.23 | 24137 |
135 | Develop | [c++] BHO 프로그램 동작 원리.. 간단하게.. | hooni | 2013.04.23 | 43143 |
134 | Develop | [C++] 18일차 과제물, String 클래스 디자인 【 C++ 문제 】 | hooni | 2013.04.23 | 7055 |
133 | Develop |
[c#]업글 뉴 툴바 개인적으로 만든거.. (new) ㅋㅋ
![]() |
hooni | 2013.04.23 | 7651 |
132 | Develop |
[c#]뉴 툴바 개인적으로 만든거.. (old)
![]() |
hooni | 2013.04.23 | 4272 |
131 | Develop |
[c#]뉴 툴바 개인적으로 만든거.. (new)
![]() |
hooni | 2013.04.23 | 7724 |
130 | Develop | [c#] 파일(File) 쓰기 ㅎㅎ | hooni | 2013.04.23 | 13316 |