if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
Intent action = new Intent(Intent.ACTION_VIEW).setClass(getApplicationContext(),MainActivity.class);
ShortcutManager shortcutManager = getApplication().getSystemService(ShortcutManager.class);
if (shortcutManager.isRequestPinShortcutSupported()) {
ShortcutInfo pinShortcutInfo = new ShortcutInfo.Builder(getApplicationContext(), "TEST_APP")
.setIntent(action)
.setShortLabel("TEST_APP")
.setIcon(Icon.createWithResource(getApplicationContext(), R.mipmap.ic_launcher)).build(); //아이콘설정
Intent pinnedShortcutCallbackIntent = shortcutManager.createShortcutResultIntent(pinShortcutInfo);
PendingIntent successCallback = PendingIntent.getBroadcast(getApplicationContext(), 0, pinnedShortcutCallbackIntent, 0);
shortcutManager.requestPinShortcut(pinShortcutInfo, successCallback.getIntentSender());
}
}
else {
Intent shortcutIntent = new Intent(Intent.ACTION_MAIN);
shortcutIntent.addCategory(Intent.CATEGORY_LAUNCHER);
shortcutIntent.setClassName(getApplicationContext(), getClass().getName());
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Intent intent = new Intent();
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "TEST_APP");
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
Intent.ShortcutIconResource.fromContext(getApplicationContext(), R.mipmap.ic_launcher));
intent.putExtra("duplicate", false);
intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
sendBroadcast(intent);
}
바로가기 아이콘을 생성하기 위한 코드입니다.
근데 이것을 일반적인 버튼 리스너 및 다이얼로그 버튼리스너 안에서 작성시 앱 아이콘 생성 이후
터치 시 애플리케이션이 설치되지않았습니다.
라는 문구가 나옵니다.
왜 리스너 안에서 사용을 하면 문제가 생기나요?