Develop
2016.11.15 14:38
[android] How can I place app icon on launcher home screen?
조회 수 1443 댓글 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,
- 안드로이드,
- 바탕화면,
- 단축키,
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
1125 | Etc | 스파이웨어(BHO) 탐지하는 방법.. | hooni | 2013.04.23 | 44506 |
1124 | Develop | [android] ListView+ArrayAdapter 테스트 | hooni | 2013.04.23 | 43979 |
1123 | Develop | [android] 화면 전환(가로/세로)시 설정 | hooni | 2013.04.23 | 43447 |
1122 | Develop | [c++] BHO 프로그램 동작 원리.. 간단하게.. | hooni | 2013.04.23 | 43173 |
1121 | System/OS | [linux] 네트웍 트래픽 모니터링(MRTG) | hooni | 2003.04.23 | 42746 |
1120 | Develop | [ios] 미스터피자(Mr.pizza) 어플 | hooni | 2013.04.23 | 42723 |
1119 | Develop | [java] 스트러츠(Struts) 세팅 ㅋㅋ | hooni | 2013.04.23 | 42411 |
1118 | Etc | [용어] POC, Pilot, BMT에 대한 IT 업계에서 통용되는 의미 | hooni | 2014.01.02 | 42086 |
1117 | System/OS | [ms-sql] 서브스트링(substring), 프로시저(SP) 작성 예제 | hooni | 2013.04.23 | 41420 |
1116 | System/OS | [dos] 노트북 백업 스크립트 xcopy 명령 예제 | hooni | 2003.04.23 | 40886 |
1115 | Develop | [android] 개발 환경 세팅 따라하기 ㅋㅋ | hooni | 2013.04.23 | 40475 |
1114 | System/OS | [mac] 맥에서 APM(apache,php,mysql) 구성하기 | hooni | 2013.04.23 | 38857 |