Contents

조회 수 1246 댓글 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
번호 분류 제목 글쓴이 날짜 조회 수
1125 Develop [ios] APNS, Remote Push 사용자가 수신을 동의했는지 확인하기 hooni 2018.10.19 1234
1124 Develop [ios] APNS, Remote Push 수신 시점에서 앱의 3가지 실행 상태 hooni 2018.10.19 949
1123 Develop [ios] Swift 4 String, Date, DateFormatter 예제 hooni 2018.10.18 1378
1122 System/OS Mac에서 Node.js 설치하기 file hooni 2018.09.28 4171
1121 System/OS 서버 확장을 위한 두 가지 방법 file hooni 2018.08.29 2081
1120 Develop [ios] Requesting Location Permissions in iOS file hooni 2018.08.18 1583
1119 Develop [PHP] Mac OS에서 PHP 7 설치하기 file hooni 2018.05.11 4861
1118 Develop [php] Connect to Firebase Console in Laravel file hooni 2018.05.09 3089
1117 Develop [api] 인스타그램 API Access_Token 발급 방법 (Instagram API) 3 file hooni 2018.04.05 7501
1116 Develop [api] 인스타그램에서 최신 이미지 가져오기 (Using Instagram API) 20 file hooni 2018.04.05 11808
1115 Develop [js] Click button copy to clipboard hooni 2018.04.05 1153
1114 Develop [php] Laravel 4. twitter bootstrap 적용하기 hooni 2018.04.05 2523
Board Pagination Prev 1 2 3 4 5 6 7 8 9 10 ... 98 Next
/ 98