조회 수 6362 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄

홈화면에 아이콘 추가하기. ㅋㄷ


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);
}


?

List of Articles
번호 분류 제목 글쓴이 날짜 조회 수
1113 Develop [ios] iOS 4.0 beta 에서 3.1.3으로 다운그레이드 하는 법 file hooni 2013.04.23 41091
1112 System/OS CentOS 6.5 USB 설치 6 file hooni 2013.12.18 39981
1111 Develop [js] jQuery 충돌 회피 hooni 2013.12.17 39462
1110 System/OS [linux] 처음 설치부터 APM 설치까지 (업데이트 할 것) hooni 2013.04.23 39456
1109 System/OS 맥에서 파일공유 (윈도우,맥) file hooni 2013.04.25 38343
1108 Develop [ios] iOS 6.0 이상 회전 하기 (이전 버전과 비교 변경 부분) file hooni 2014.01.27 38249
1107 Develop [js] jQuery 치트 시트 hooni 2013.12.18 37209
1106 Develop [php] 몽이가 준 ajax 채팅 소스 ㅋㅋ file hooni 2013.04.23 37126
1105 Develop [lego] 세그웨이 이것만 볼것.. ㅎㅎ file hooni 2013.04.23 36843
1104 System/OS [sql] 조회구문(select)에서 중복 데이터를 한 번만 출력 (distinct) 1 hooni 2013.04.23 35645
1103 System/OS [mac] 맥에서 슬립(잠자기) 모드 진입을 막는 방법~ hooni 2013.10.10 35283
1102 Develop 베지어 곡선(Bézier curve) 알고리즘(spline 곡선) 3 file hooni 2013.04.23 35261
1101 Develop [c++] 웹폼(webform)전송과 http 파일 업로드 샘플 file hooni 2013.04.23 34991
1100 System/OS Mac OS X - Apache+PHP+MySQL 환경 서버 hooni 2013.04.25 34805
1099 Develop [js] 웹페이지에서 특정 엘리먼트 드래그, 복사, 컨텍스트메뉴, 키보드 막기 hooni 2013.11.04 34793
1098 Develop [c] C로 구현한 CGI - 방명록 file hooni 2003.04.23 34458
Board Pagination Prev 1 3 4 5 6 7 ... 74 Next
/ 74