Contents

조회 수 1265 댓글 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
번호 분류 제목 글쓴이 날짜 조회 수
393 Etc [link] 유용한 사이트 링크. hooni 2013.08.19 71459
392 Develop [ios] 앱에서 다른 앱 실행시키기 file hooni 2013.09.05 18536
391 Develop [ios] None IB vs. StoryBoard 샘플 소스 file hooni 2013.09.06 16932
390 Develop [python] 애니팡, 캔디팡 매크로 file hooni 2013.09.06 17322
389 Develop [ios] Hybrid 앱 스터디 발표 자료 file hooni 2013.09.06 13712
388 Etc 영어. 외우면 도움되는 필수영어회화 표현 file hooni 2013.09.09 20950
387 Develop [ios] 간단한 방법으로 OS버전 확인하기. hooni 2013.09.24 13312
386 System/OS [mac] SVN 1.8 업데이트 방법 hooni 2013.09.24 14569
385 Etc [svn] 콘솔에서 svn 사용시 레티나용 이미지 add 안될 때.. hooni 2013.09.25 37496
384 Develop [ios] UIView에서 상위 UIViewController 가져오기 hooni 2013.09.27 20159
383 Develop [ios] GCD 변수 사용 예제 hooni 2013.10.01 12114
382 System/OS [linux] 우분투 APM + phpmyadmin 설치 hooni 2013.10.07 49325
Board Pagination Prev 1 ... 61 62 63 64 65 66 67 68 69 70 ... 98 Next
/ 98