DBILITY

android shortcut 본문

android/java

android shortcut

DBILITY 2024. 5. 2. 20:38
반응형
<uses-permission android:name="android.permission.INSTALL_SHORTCUT" />

퍼미션은 없어도 되는 것 같은데

SharedPreferences sharedPreferences = getSharedPreferences("FIRST_LAUNCH", Context.MODE_PRIVATE);
if (sharedPreferences.getBoolean("FIRST_LAUNCH", true)) {
    sharedPreferences.edit().putBoolean("FIRST_LAUNCH", false).commit();
    if (ShortcutManagerCompat.isRequestPinShortcutSupported(this)) {
        ShortcutInfoCompat shortcutInfoCompat = new ShortcutInfoCompat.Builder(this, "#0")
                .setIntent(new Intent(this, RetrofitActivity.class)
                        .setAction(Intent.ACTION_MAIN))
                .setShortLabel(getString(R.string.app_name))
                .setIcon(IconCompat.createWithResource(this, R.drawable.icon))
                .build();
        ShortcutManagerCompat.requestPinShortcut(this, shortcutInfoCompat, null);
        Toast.makeText(this, "바로가기가 생성되었습니다", Toast.LENGTH_SHORT).show();
    }
}
반응형
Comments