Contents

Views 1259 Comment 0
?

Shortcut

PrevPrev Article

NextNext Article

Larger Font Smaller Font Up Down Go comment Print
?

Shortcut

PrevPrev Article

NextNext Article

Larger Font Smaller Font Up Down Go comment Print

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


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
No. Category Subject Author Date Views
1089 Develop XE Core 1.8.18 본문 작성시 태그(html) 사라지는 버그 file hooni 2016.04.21 862
1088 Develop [android] N-Puzzle 게임 file hooni 2015.07.09 863
1087 Develop [ios] iOS 앱 아이콘을 만드는 유틸 file hooni 2015.01.03 867
1086 Develop [ios] ViewController Push할 때 애니메이션 효과 hooni 2015.10.23 868
1085 Develop [git] 쉬운 버전관리 Git 설명 hooni 2015.08.18 870
1084 PPT [ppt] Information Security 발표 자료 (@Team Study 2012.11.15) file hooni 2015.07.22 876
1083 System/OS [mac] OS X 엘 캐피탄에서 Soudflower 사용하기 2 file hooni 2016.10.03 876
1082 Develop [c] RSA 암호화 구현(gmp 라이브러리 활용) file hooni 2016.10.03 878
1081 System/OS [mac] How to uninstall MySQL on Mac OS. hooni 2017.11.08 882
1080 Develop [js] AngularJS 란? file hooni 2015.11.26 883
1079 Develop [ios] APNS에 사용할 인증서 만들기 (KeyChain에 있는 인증서 Export) file hooni 2015.01.03 888
1078 System/OS 맥에서 포트 확인하고 닫기 (mac) hooni 2022.03.22 888
Board Pagination Prev 1 ... 3 4 5 6 7 8 9 10 11 12 ... 98 Next
/ 98