if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
ShortcutManager shortcutManager = getSystemService(ShortcutManager.class);
// Создание ярлыка
ShortcutInfo shortcut = new ShortcutInfo.Builder(this, "shortcut_id")
.setShortLabel("My App")
.setLongLabel("Open My App")
.setIcon(Icon.createWithResource(this, R.drawable.ic_launcher_foreground))
.setIntent(new Intent(Intent.ACTION_MAIN, Uri.EMPTY, this, MainActivity.class))
.build();
// Установка ярлыка
shortcutManager.setDynamicShortcuts(Collections.singletonList(shortcut));
// Задержка перед удалением (например, 1 секунда)
new Handler().postDelayed(() -> {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
ShortcutManager manager = getSystemService(ShortcutManager.class);
manager.removeDynamicShortcuts(Collections.singletonList("shortcut_id"));
}
}, 1000); // 1 секунда
} else {
Log.d("MainActivity", "Android version is below N_MR1. Cannot use ShortcutManager.");
}
// Отключаем Activtiy
ComponentName cn = new ComponentName("com.example.app", "com.example.app.MainActivity");
pm.setComponentEnabledSetting(cn, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
PackageManager p = getPackageManager();
ComponentName componentName = new ComponentName(this, MainActivity.class);
p.setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
PackageManager pm = getPackageManager();
ActivityInfo ai = pm.getActivityInfo(getComponentName(), PackageManager.GET_META_DATA);
ai.icon = R.drawable.transparent_icon; // Прозрачная иконка
ai.logo = R.drawable.transparent_icon;
Intent intent = new Intent("android.intent.action.MAIN");
intent.setComponent(new ComponentName("com.android.settings", "com.android.settings.Settings$AppDrawerSettingsActivity"));
startActivity(intent);