List of usage examples for android.content.pm ShortcutManager getDynamicShortcuts
@NonNull
public List<ShortcutInfo> getDynamicShortcuts()
From source file:com.farmerbb.taskbar.MainActivity.java
private void proceedWithAppLaunch(Bundle savedInstanceState) { setContentView(R.layout.main);// w w w .ja v a 2 s . c o m ActionBar actionBar = getSupportActionBar(); if (actionBar != null) { actionBar.setCustomView(R.layout.switch_layout); actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_TITLE | ActionBar.DISPLAY_SHOW_CUSTOM); } theSwitch = (SwitchCompat) findViewById(R.id.the_switch); if (theSwitch != null) { final SharedPreferences pref = U.getSharedPreferences(this); theSwitch.setChecked(pref.getBoolean("taskbar_active", false)); theSwitch.setOnCheckedChangeListener((compoundButton, b) -> { if (b) { if (U.canDrawOverlays(this)) { boolean firstRun = pref.getBoolean("first_run", true); startTaskbarService(); if (firstRun && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !U.isSystemApp(this)) { ApplicationInfo applicationInfo = null; try { applicationInfo = getPackageManager().getApplicationInfo(BuildConfig.APPLICATION_ID, 0); } catch (PackageManager.NameNotFoundException e) { /* Gracefully fail */ } if (applicationInfo != null) { AppOpsManager appOpsManager = (AppOpsManager) getSystemService( Context.APP_OPS_SERVICE); int mode = appOpsManager.checkOpNoThrow(AppOpsManager.OPSTR_GET_USAGE_STATS, applicationInfo.uid, applicationInfo.packageName); if (mode != AppOpsManager.MODE_ALLOWED) { AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this); builder.setTitle(R.string.pref_header_recent_apps) .setMessage(R.string.enable_recent_apps) .setPositiveButton(R.string.action_ok, (dialog, which) -> { try { startActivity( new Intent(Settings.ACTION_USAGE_ACCESS_SETTINGS)); U.showToastLong(MainActivity.this, R.string.usage_stats_message); } catch (ActivityNotFoundException e) { U.showErrorDialog(MainActivity.this, "GET_USAGE_STATS"); } }).setNegativeButton(R.string.action_cancel, null); AlertDialog dialog = builder.create(); dialog.show(); } } } } else { U.showPermissionDialog(MainActivity.this); compoundButton.setChecked(false); } } else stopTaskbarService(); }); } if (savedInstanceState == null) { if (!getIntent().hasExtra("theme_change")) getFragmentManager().beginTransaction() .replace(R.id.fragmentContainer, new AboutFragment(), "AboutFragment").commit(); else getFragmentManager().beginTransaction() .replace(R.id.fragmentContainer, new AppearanceFragment(), "AppearanceFragment").commit(); } if (!BuildConfig.APPLICATION_ID.equals(BuildConfig.BASE_APPLICATION_ID) && freeVersionInstalled()) { final SharedPreferences pref = U.getSharedPreferences(this); if (!pref.getBoolean("dont_show_uninstall_dialog", false)) { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(R.string.settings_imported_successfully).setMessage(R.string.import_dialog_message) .setPositiveButton(R.string.action_uninstall, (dialog, which) -> { pref.edit().putBoolean("uninstall_dialog_shown", true).apply(); try { startActivity(new Intent(Intent.ACTION_DELETE, Uri.parse("package:" + BuildConfig.BASE_APPLICATION_ID))); } catch (ActivityNotFoundException e) { /* Gracefully fail */ } }); if (pref.getBoolean("uninstall_dialog_shown", false)) builder.setNegativeButton(R.string.action_dont_show_again, (dialogInterface, i) -> pref.edit() .putBoolean("dont_show_uninstall_dialog", true).apply()); AlertDialog dialog = builder.create(); dialog.show(); dialog.setCancelable(false); } if (!pref.getBoolean("uninstall_dialog_shown", false)) { if (theSwitch != null) theSwitch.setChecked(false); SharedPreferences.Editor editor = pref.edit(); String iconPack = pref.getString("icon_pack", BuildConfig.BASE_APPLICATION_ID); if (iconPack.contains(BuildConfig.BASE_APPLICATION_ID)) { editor.putString("icon_pack", BuildConfig.APPLICATION_ID); } else { U.refreshPinnedIcons(this); } editor.putBoolean("first_run", true); editor.apply(); } } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) { ShortcutManager shortcutManager = getSystemService(ShortcutManager.class); if (shortcutManager.getDynamicShortcuts().size() == 0) { Intent intent = new Intent(Intent.ACTION_MAIN); intent.setClass(this, StartTaskbarActivity.class); intent.putExtra("is_launching_shortcut", true); ShortcutInfo shortcut = new ShortcutInfo.Builder(this, "start_taskbar") .setShortLabel(getString(R.string.start_taskbar)) .setIcon(Icon.createWithResource(this, R.drawable.shortcut_icon_start)).setIntent(intent) .build(); Intent intent2 = new Intent(Intent.ACTION_MAIN); intent2.setClass(this, ShortcutActivity.class); intent2.putExtra("is_launching_shortcut", true); ShortcutInfo shortcut2 = new ShortcutInfo.Builder(this, "freeform_mode") .setShortLabel(getString(R.string.pref_header_freeform)) .setIcon(Icon.createWithResource(this, R.drawable.shortcut_icon_freeform)) .setIntent(intent2).build(); shortcutManager.setDynamicShortcuts(Arrays.asList(shortcut, shortcut2)); } } }
From source file:org.deviceconnect.android.deviceplugin.demo.DemoSettingFragment.java
private boolean isCreatedShortcut() { if (DEBUG) {/*from w w w .ja va2s .co m*/ Log.d(TAG, "DemoPageSetting: isCreatedShortcut"); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) { ShortcutManager shortcutManager = mShortcutManager; List<ShortcutInfo> infoList = shortcutManager.getPinnedShortcuts(); if (DEBUG) { Log.d(TAG, "DemoPageSetting: isCreatedShortcut: PinnedShortcuts=" + infoList.size()); Log.d(TAG, "DemoPageSetting: isCreatedShortcut: DynamicShortcuts=" + shortcutManager.getDynamicShortcuts()); } for (ShortcutInfo info : infoList) { if (DEBUG) { Log.d(TAG, "DemoPageSetting: isCreatedShortcut: info=" + info.getPackage()); } if (info.getId().equals(CAMERA_DEMO_SHORTCUT_ID)) { return true; } } return false; } else { return false; } }