android.content.pm.ShortcutManager Java Examples
The following examples show how to use
android.content.pm.ShortcutManager.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: QuickToggleShortcut.java From ShadowsocksRR with Apache License 2.0 | 8 votes |
@Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); String action = getIntent().getAction(); if (Intent.ACTION_CREATE_SHORTCUT.equals(action)) { setResult(Activity.RESULT_OK, new Intent() .putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(this, QuickToggleShortcut.class)) .putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.quick_toggle)) .putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(this, R.mipmap.ic_launcher))); finish(); } else { mServiceBoundContext.attachService(); if (Build.VERSION.SDK_INT >= 25) { ShortcutManager service = getSystemService(ShortcutManager.class); if (service != null) { service.reportShortcutUsed("toggle"); } } } }
Example #2
Source File: DemoSettingFragment.java From DeviceConnect-Android with MIT License | 6 votes |
private boolean isCreatedShortcut() { if (DEBUG) { 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; } }
Example #3
Source File: MainActivity.java From Wrox-ProfessionalAndroid-4E with Apache License 2.0 | 6 votes |
@RequiresApi(api = Build.VERSION_CODES.N_MR1) private void listing19_28(String destination) { // Listing 19-28: Creating and adding dynamic App Shortcuts ShortcutManager shortcutManager = (ShortcutManager) getSystemService(Context.SHORTCUT_SERVICE); Intent navIntent = new Intent(this, MainActivity.class); navIntent.setAction(Intent.ACTION_VIEW); navIntent.putExtra(DESTINATION_EXTRA, destination); String id = "dynamicDest" + destination; ShortcutInfo shortcut = new ShortcutInfo.Builder(this, id) .setShortLabel(destination) .setLongLabel("Navigate to " + destination) .setDisabledMessage("Navigation Shortcut Disabled") .setIcon(Icon.createWithResource(this, R.mipmap.ic_launcher)) .setIntent(navIntent) .build(); shortcutManager.setDynamicShortcuts(Arrays.asList(shortcut)); }
Example #4
Source File: Gander.java From Gander with Apache License 2.0 | 6 votes |
/** * Register an app shortcut to launch the Gander UI directly from the launcher on Android 7.0 and above. * * @param context A valid {@link Context} * @return The id of the added shortcut (<code>null</code> if this feature is not supported on the device). * It can be used if you want to remove this shortcut later on. */ @TargetApi(Build.VERSION_CODES.N_MR1) @SuppressWarnings("WeakerAccess") @Nullable public static String addAppShortcut(Context context) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) { final String id = context.getPackageName() + ".gander_ui"; final ShortcutManager shortcutManager = context.getSystemService(ShortcutManager.class); final ShortcutInfo shortcut = new ShortcutInfo.Builder(context, id).setShortLabel("Gander") .setLongLabel("Open Gander") .setIcon(Icon.createWithResource(context, R.drawable.gander_ic_shortcut_primary_24dp)) .setIntent(getLaunchIntent(context).setAction(Intent.ACTION_VIEW)) .build(); shortcutManager.addDynamicShortcuts(Collections.singletonList(shortcut)); return id; } else { return null; } }
Example #5
Source File: DynamicShortcutManager.java From volume_control_android with MIT License | 6 votes |
public static void setShortcuts(Activity activity, SoundProfile[] soundProfiles) { final List<ShortcutInfo> shortcutInfos = new ArrayList<>(); for (SoundProfile soundProfile : soundProfiles) { if (!soundProfile.name.isEmpty()) { shortcutInfos.add(createShortcutInfo(activity, soundProfile)); } } ShortcutManager shortcutManager = activity.getSystemService(ShortcutManager.class); if (shortcutManager.getMaxShortcutCountPerActivity() < shortcutInfos.size()) { int last = shortcutInfos.size() - 1; int first = last - shortcutManager.getMaxShortcutCountPerActivity(); shortcutManager.setDynamicShortcuts(shortcutInfos.subList(first, last)); } else { shortcutManager.setDynamicShortcuts(shortcutInfos); } }
Example #6
Source File: ShortcutHelper.java From zapp with MIT License | 6 votes |
/** * Adds the given channel as shortcut to the launcher icon. * Only call on api level >= 25. * * @param context to access system services * @param channel channel to create a shortcut for * @return true if the channel could be added */ @TargetApi(25) public static boolean addShortcutForChannel(Context context, ChannelModel channel) { ShortcutManager shortcutManager = context.getSystemService(ShortcutManager.class); if (shortcutManager == null || shortcutManager.getDynamicShortcuts().size() >= 4) { return false; } ShortcutInfo shortcut = new ShortcutInfo.Builder(context, channel.getId()) .setShortLabel(channel.getName()) .setLongLabel(channel.getName()) .setIcon(Icon.createWithResource(context, channel.getDrawableId())) .setIntent(ChannelDetailActivity.getStartIntent(context, channel.getId())) .build(); try { return shortcutManager.addDynamicShortcuts(Collections.singletonList(shortcut)); } catch (IllegalArgumentException e) { // too many shortcuts return false; } }
Example #7
Source File: UIUtils.java From rebootmenu with GNU General Public License v3.0 | 6 votes |
/** * 启动器添加快捷方式 * * @param context 上下文 * @param titleRes 标题资源id * @param iconRes 图标资源id * @param shortcutAct Shortcut额外 * @param isForce 是否是root强制模式 * @see com.ryuunoakaihitomi.rebootmenu.activity.Shortcut */ public static void addLauncherShortcut(@NonNull Context context, @StringRes int titleRes, @DrawableRes int iconRes, int shortcutAct, boolean isForce) { new DebugLog("addLauncherShortcut", DebugLog.LogLevel.V); String forceToken = isForce ? "*" : ""; String title = forceToken + context.getString(titleRes); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) context.sendBroadcast(new Intent("com.android.launcher.action.INSTALL_SHORTCUT") .putExtra("duplicate", false) .putExtra(Intent.EXTRA_SHORTCUT_NAME, title) .putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(context, iconRes)) .putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(context, Shortcut.class) .putExtra(Shortcut.extraTag, shortcutAct))); else { ShortcutInfo shortcutInfo = new ShortcutInfo.Builder(context, "o_launcher_shortcut:" + shortcutAct) .setShortLabel(title) .setIcon(Icon.createWithResource(context, iconRes)) .setIntent(new Intent(context, Shortcut.class) .putExtra(Shortcut.extraTag, shortcutAct) .setAction(Intent.ACTION_VIEW)) .build(); new DebugLog("addLauncherShortcut: requestPinShortcut:" + context.getSystemService(ShortcutManager.class).requestPinShortcut(shortcutInfo, null)); } }
Example #8
Source File: AppShortcutsHelper.java From rcloneExplorer with MIT License | 6 votes |
@RequiresApi(api = Build.VERSION_CODES.N_MR1) public static void addRemoteToAppShortcuts(Context context, RemoteItem remoteItem, String id) { ShortcutManager shortcutManager = context.getSystemService(ShortcutManager.class); if (shortcutManager == null) { return; } Intent intent = new Intent(Intent.ACTION_MAIN, Uri.EMPTY, context, MainActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); intent.putExtra(APP_SHORTCUT_REMOTE_NAME, remoteItem.getName()); ShortcutInfo shortcut = new ShortcutInfo.Builder(context, id) .setShortLabel(remoteItem.getName()) .setIcon(Icon.createWithResource(context, AppShortcutsHelper.getRemoteIcon(remoteItem.getType(), remoteItem.isCrypt()))) .setIntent(intent) .build(); shortcutManager.addDynamicShortcuts(Collections.singletonList(shortcut)); }
Example #9
Source File: AppShortcutsHelper.java From rcloneExplorer with MIT License | 6 votes |
public static void reportAppShortcutUsage(Context context, String remoteName) { if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.N_MR1) { return; } SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); Set<String> appShortcutIds = sharedPreferences.getStringSet(context.getString(R.string.shared_preferences_app_shortcuts), new HashSet<String>()); String id = getUniqueIdFromString(remoteName); if (appShortcutIds.contains(id)) { ShortcutManager shortcutManager = context.getSystemService(ShortcutManager.class); if (shortcutManager == null) { return; } shortcutManager.reportShortcutUsed(id); } }
Example #10
Source File: U.java From Taskbar with Apache License 2.0 | 6 votes |
public static void pinAppShortcut(Context context) { if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { ShortcutManager mShortcutManager = context.getSystemService(ShortcutManager.class); if(mShortcutManager.isRequestPinShortcutSupported()) { ShortcutInfo pinShortcutInfo = new ShortcutInfo.Builder(context, "freeform_mode").build(); mShortcutManager.requestPinShortcut(pinShortcutInfo, null); } else showToastLong(context, R.string.tb_pin_shortcut_not_supported); } else { Intent intent = ShortcutUtils.getShortcutIntent(context); intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT"); intent.putExtra("duplicate", false); Intent homeIntent = new Intent(Intent.ACTION_MAIN); homeIntent.addCategory(Intent.CATEGORY_HOME); ResolveInfo defaultLauncher = context.getPackageManager().resolveActivity(homeIntent, PackageManager.MATCH_DEFAULT_ONLY); intent.setPackage(defaultLauncher.activityInfo.packageName); context.sendBroadcast(intent); showToast(context, R.string.tb_shortcut_created); } }
Example #11
Source File: MainActivity.java From SecondScreen with Apache License 2.0 | 6 votes |
private void setLauncherShortcuts() { 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.setClassName(BuildConfig.APPLICATION_ID, TaskerQuickActionsActivity.class.getName()); intent.putExtra("launched-from-app", true); ShortcutInfo shortcut = new ShortcutInfo.Builder(this, "quick_actions") .setShortLabel(getString(R.string.label_quick_actions)) .setIcon(Icon.createWithResource(this, R.drawable.shortcut_icon)) .setIntent(intent) .build(); shortcutManager.setDynamicShortcuts(Collections.singletonList(shortcut)); } } }
Example #12
Source File: Helper.java From AppOpsX with MIT License | 6 votes |
@RequiresApi(api = Build.VERSION_CODES.N_MR1) private static void updataShortcuts(Context context, List<AppInfo> items) { ShortcutManager shortcutManager = context.getSystemService(ShortcutManager.class); List<ShortcutInfo> shortcutInfoList = new ArrayList<>(); int max = shortcutManager.getMaxShortcutCountPerActivity(); for (int i = 0; i < max && i < items.size(); i++) { AppInfo appInfo = items.get(i); ShortcutInfo.Builder shortcut = new ShortcutInfo.Builder(context, appInfo.packageName); shortcut.setShortLabel(appInfo.appName); shortcut.setLongLabel(appInfo.appName); shortcut.setIcon( Icon.createWithBitmap(drawableToBitmap(LocalImageLoader.getDrawable(context, appInfo)))); Intent intent = new Intent(context, AppPermissionActivity.class); intent.putExtra(AppPermissionActivity.EXTRA_APP_PKGNAME, appInfo.packageName); intent.putExtra(AppPermissionActivity.EXTRA_APP_NAME, appInfo.appName); intent.setAction(Intent.ACTION_DEFAULT); shortcut.setIntent(intent); shortcutInfoList.add(shortcut.build()); } shortcutManager.setDynamicShortcuts(shortcutInfoList); }
Example #13
Source File: ShortcutHelper.java From shortcut-helper with Apache License 2.0 | 6 votes |
public ShortcutHelper createShortcutList(@NonNull List<Shortcut> shortcuts) { if (Build.VERSION.SDK_INT < 25) { return this; } mShortcutManager = mActivity.getSystemService(ShortcutManager.class); for (int i=0; i<shortcuts.size(); i++) { if (i < mShortcutManager.getMaxShortcutCountPerActivity()) { String shortcutId = shortcuts.get(i).getShortLabel().replaceAll("\\s+","").toLowerCase() + "_shortcut"; ShortcutInfo shortcut = new ShortcutInfo.Builder(mActivity, shortcutId) .setShortLabel(shortcuts.get(i).getShortLabel()) .setLongLabel(shortcuts.get(i).getLongLabel()) .setIcon(Icon.createWithResource(mActivity, shortcuts.get(i).getIconResource())) .setIntent(shortcuts.get(i).getIntent()) .build(); mShortcutInfos.add(shortcut); } } return this; }
Example #14
Source File: ShortcutsUtils.java From shortrain with MIT License | 6 votes |
public static int getNextRailNumber(ShortcutManager shortcutManager) { List<ShortcutInfo> shortcuts = shortcutManager.getPinnedShortcuts(); int newRailId = -1; for (ShortcutInfo shortcutInfo : shortcuts) { String id = shortcutInfo.getId(); if (isRailShortcut(id)) { int railId = getRailNumber(id); if (railId > newRailId) { newRailId = railId; } } } newRailId++; return newRailId; }
Example #15
Source File: ShortcutsUtils.java From shortrain with MIT License | 6 votes |
public static List<RailInfo> getRails(ShortcutManager shortcutManager) { List<ShortcutInfo> shortcuts = shortcutManager.getPinnedShortcuts(); List<RailInfo> rails = new ArrayList<>(); for (ShortcutInfo shortcutInfo : shortcuts) { String id = shortcutInfo.getId(); if (isRailShortcut(id)) { PersistableBundle extras = shortcutInfo.getExtras(); if (extras != null) { int[] posArray = extras.getIntArray(RailActionActivity.RAIL_RECT_KEY); int rotation = extras.getInt(RailActionActivity.RAIL_ROTATION_KEY); assert posArray != null; rails.add(new RailInfo(posArray[0], posArray[1], rotation)); } } } return rails; }
Example #16
Source File: ScannerActivity.java From Maying with Apache License 2.0 | 6 votes |
@Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.layout_scanner); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); toolbar.setTitle(getTitle()); toolbar.setNavigationIcon(R.drawable.abc_ic_ab_back_material); toolbar.setNavigationOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { navigateUp(); } }); scannerView = (ZXingScannerView) findViewById(R.id.scanner); if (Build.VERSION.SDK_INT >= 25) { ShortcutManager service = getSystemService(ShortcutManager.class); if (service != null) { service.reportShortcutUsed("scan"); } } }
Example #17
Source File: AegisApplication.java From Aegis with GNU General Public License v3.0 | 6 votes |
@RequiresApi(api = Build.VERSION_CODES.N_MR1) private void initAppShortcuts() { ShortcutManager shortcutManager = getSystemService(ShortcutManager.class); if (shortcutManager == null) { return; } Intent intent = new Intent(this, MainActivity.class); intent.putExtra("action", "scan"); intent.setAction(Intent.ACTION_MAIN); ShortcutInfo shortcut = new ShortcutInfo.Builder(this, "shortcut_new") .setShortLabel(getString(R.string.new_entry)) .setLongLabel(getString(R.string.add_new_entry)) .setIcon(Icon.createWithResource(this, R.drawable.ic_qr_code)) .setIntent(intent) .build(); shortcutManager.setDynamicShortcuts(Collections.singletonList(shortcut)); }
Example #18
Source File: QuickToggleShortcut.java From Maying with Apache License 2.0 | 6 votes |
@Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); String action = getIntent().getAction(); if (Intent.ACTION_CREATE_SHORTCUT.equals(action)) { setResult(Activity.RESULT_OK, new Intent() .putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(this, QuickToggleShortcut.class)) .putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.quick_toggle)) .putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(this, R.mipmap.ic_launcher))); finish(); } else { mServiceBoundContext.attachService(); if (Build.VERSION.SDK_INT >= 25) { ShortcutManager service = getSystemService(ShortcutManager.class); if (service != null) { service.reportShortcutUsed("toggle"); } } } }
Example #19
Source File: LauncherShortcutActivity.java From 365browser with Apache License 2.0 | 6 votes |
/** * Adds a "New incognito tab" dynamic launcher shortcut. * @param context The context used to retrieve the system {@link ShortcutManager}. * @return True if addint the shortcut has succeeded. False if the call fails due to rate * limiting. See {@link ShortcutManager#addDynamicShortcuts}. */ @TargetApi(Build.VERSION_CODES.N_MR1) private static boolean addIncognitoLauncherShortcut(Context context) { Intent intent = new Intent(LauncherShortcutActivity.ACTION_OPEN_NEW_INCOGNITO_TAB); intent.setPackage(context.getPackageName()); intent.setClass(context, LauncherShortcutActivity.class); ShortcutInfo shortcut = new ShortcutInfo.Builder(context, DYNAMIC_OPEN_NEW_INCOGNITO_TAB_ID) .setShortLabel(context.getResources().getString( R.string.accessibility_tabstrip_incognito_identifier)) .setLongLabel( context.getResources().getString(R.string.menu_new_incognito_tab)) .setIcon(Icon.createWithResource(context, R.drawable.shortcut_incognito)) .setIntent(intent) .build(); ShortcutManager shortcutManager = context.getSystemService(ShortcutManager.class); return shortcutManager.addDynamicShortcuts(Arrays.asList(shortcut)); }
Example #20
Source File: WechatContactsActivity.java From GcmForMojo with GNU General Public License v3.0 | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_wechat_contacts); //Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); //setSupportActionBar(toolbar); WechatFriendArrayList = MyApplication.getInstance().getWechatFriendArrayList(); WechatFriendGroups = MyApplication.getInstance().getWechatFriendGroups(); init(); // Android 7.1 用于提升Shortcut启动性能 if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) { ShortcutManager mShortcutManager = getSystemService(ShortcutManager.class); mShortcutManager.reportShortcutUsed("static_wechat_contacts"); } }
Example #21
Source File: ShortcutHelper.java From Hentoid with Apache License 2.0 | 5 votes |
public static void buildShortcuts(Context context) { // TODO: Loop across all activities List<ShortcutInfo> shortcuts = new ArrayList<>(); shortcuts.add(buildShortcut(context, Site.NHENTAI)); ShortcutManager shortcutManager = context.getSystemService(ShortcutManager.class); if (shortcutManager != null) shortcutManager.setDynamicShortcuts(shortcuts); }
Example #22
Source File: MainActivity.java From ui with Apache License 2.0 | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); logger = (TextView) findViewById(R.id.logger); //get an instance of the shortcurManager mShortcutManager = getSystemService(ShortcutManager.class); //ShortcutManager.class is android, not a class I created. }
Example #23
Source File: LauncherShortcutActivity.java From 365browser with Apache License 2.0 | 5 votes |
/** * Removes the dynamic "New incognito tab" launcher shortcut. * @param context The context used to retrieve the system {@link ShortcutManager}. */ @TargetApi(Build.VERSION_CODES.N_MR1) private static void removeIncognitoLauncherShortcut(Context context) { List<String> shortcutList = new ArrayList<>(); shortcutList.add(DYNAMIC_OPEN_NEW_INCOGNITO_TAB_ID); ShortcutManager shortcutManager = context.getSystemService(ShortcutManager.class); shortcutManager.disableShortcuts(shortcutList); shortcutManager.removeDynamicShortcuts(shortcutList); }
Example #24
Source File: NotesDatabase.java From nextcloud-notes with GNU General Public License v3.0 | 5 votes |
void updateDynamicShortcuts(long accountId) { new Thread(() -> { if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N_MR1) { ShortcutManager shortcutManager = getContext().getApplicationContext().getSystemService(ShortcutManager.class); if (shortcutManager != null) { if (!shortcutManager.isRateLimitingActive()) { List<ShortcutInfo> newShortcuts = new ArrayList<>(); for (DBNote note : getRecentNotes(accountId)) { if (!TextUtils.isEmpty(note.getTitle())) { Intent intent = new Intent(getContext().getApplicationContext(), EditNoteActivity.class); intent.putExtra(EditNoteActivity.PARAM_NOTE_ID, note.getId()); intent.setAction(ACTION_SHORTCUT); newShortcuts.add(new ShortcutInfo.Builder(getContext().getApplicationContext(), note.getId() + "") .setShortLabel(note.getTitle() + "") .setIcon(Icon.createWithResource(getContext().getApplicationContext(), note.isFavorite() ? R.drawable.ic_star_yellow_24dp : R.drawable.ic_star_grey_ccc_24dp)) .setIntent(intent) .build()); } else { // Prevent crash https://github.com/stefan-niedermann/nextcloud-notes/issues/613 Log.e(TAG, "shortLabel cannot be empty " + note); } } Log.d(TAG, "Update dynamic shortcuts"); shortcutManager.removeAllDynamicShortcuts(); shortcutManager.addDynamicShortcuts(newShortcuts); } } } }).start(); }
Example #25
Source File: App.java From FastLib with Apache License 2.0 | 5 votes |
private void setShortcut() { if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N_MR1) { ShortcutManager shortcutManager = mContext.getSystemService(ShortcutManager.class); List<ShortcutInfo> list = new ArrayList<>(); ShortcutInfo shortGit; ShortcutInfo shortBlog; Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.jianshu.com/u/a229eee96115")); intent.setClassName(getPackageName(), MainActivity.class.getName()); intent.putExtra("url", "https://www.jianshu.com/u/a229eee96115"); Intent intentGit = new Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/AriesHoo")); intentGit.setClassName(getPackageName(), MainActivity.class.getName()); intentGit.putExtra("url", "https://github.com/AriesHoo"); shortGit = new ShortcutInfo.Builder(this, "github") .setShortLabel("GitHub") .setLongLabel("GitHub-AriesHoo") .setIcon(Icon.createWithResource(mContext, R.drawable.ic_github)) .setIntent(intentGit) .build(); shortBlog = new ShortcutInfo.Builder(this, "jianshu") .setShortLabel("简书") .setLongLabel("简书-AriesHoo") .setIcon(Icon.createWithResource(mContext, R.drawable.ic_book)) .setIntent(intent) .build(); list.add(shortGit); list.add(shortBlog); shortcutManager.setDynamicShortcuts(list); } }
Example #26
Source File: ShortcutService.java From Pix-Art-Messenger with GNU General Public License v3.0 | 5 votes |
@TargetApi(25) public void report(Contact contact) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) { ShortcutManager shortcutManager = xmppConnectionService.getSystemService(ShortcutManager.class); shortcutManager.reportShortcutUsed(getShortcutId(contact)); } }
Example #27
Source File: ShortcutHelper.java From zapp with MIT License | 5 votes |
@TargetApi(25) public static List<String> getChannelIdsOfShortcuts(Context context) { ShortcutManager shortcutManager = context.getSystemService(ShortcutManager.class); if (shortcutManager == null) { return Collections.emptyList(); } List<ShortcutInfo> shortcuts = shortcutManager.getDynamicShortcuts(); List<String> ids = new ArrayList<>(shortcuts.size()); for (ShortcutInfo shortcut : shortcuts) { ids.add(shortcut.getId()); } return ids; }
Example #28
Source File: ShortcutHelper.java From zapp with MIT License | 5 votes |
/** * Removes the given channel as shortcut from the launcher icon. * Only call on api level >= 25. * * @param context to access system services * @param channelId id of the channel you want to remove from shorcut menu */ @TargetApi(25) public static void removeShortcutForChannel(Context context, String channelId) { ShortcutManager shortcutManager = context.getSystemService(ShortcutManager.class); if (shortcutManager != null) { shortcutManager.removeDynamicShortcuts(Collections.singletonList(channelId)); } }
Example #29
Source File: LauncherIconCreator.java From ActivityLauncher with ISC License | 5 votes |
@TargetApi(26) private static void doCreateShortcut(Context context, String appName, Drawable draw, Intent intent) { ShortcutManager shortcutManager = Objects.requireNonNull(context.getSystemService(ShortcutManager.class)); if (shortcutManager.isRequestPinShortcutSupported()) { Bitmap bitmap = getBitmapFromDrawable(draw); intent.setAction(Intent.ACTION_CREATE_SHORTCUT); ShortcutInfo shortcutInfo = new ShortcutInfo.Builder(context, appName) .setShortLabel(appName) .setLongLabel(appName) .setIcon(Icon.createWithBitmap(bitmap)) .setIntent(intent) .build(); shortcutManager.requestPinShortcut(shortcutInfo, null); } else { new AlertDialog.Builder(context) .setTitle(context.getText(R.string.error_creating_shortcut)) .setMessage(context.getText(R.string.error_verbose_pin_shortcut)) .setPositiveButton(context.getText(android.R.string.ok), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // Just close dialog don't do anything dialog.cancel(); } }) .show(); } }
Example #30
Source File: NavigationActivity.java From KernelAdiutor with GNU General Public License v3.0 | 5 votes |
private void setShortcuts() { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N_MR1) return; PriorityQueue<Class<? extends Fragment>> queue = new PriorityQueue<>( (o1, o2) -> { int opened1 = AppSettings.getFragmentOpened(o1, this); int opened2 = AppSettings.getFragmentOpened(o2, this); return opened2 - opened1; }); for (Map.Entry<Integer, Class<? extends Fragment>> entry : mActualFragments.entrySet()) { Class<? extends Fragment> fragmentClass = entry.getValue(); if (fragmentClass == null || fragmentClass == SettingsFragment.class) continue; queue.offer(fragmentClass); } List<ShortcutInfo> shortcutInfos = new ArrayList<>(); ShortcutManager shortcutManager = getSystemService(ShortcutManager.class); shortcutManager.removeAllDynamicShortcuts(); for (int i = 0; i < 4; i++) { NavigationFragment fragment = findNavigationFragmentByClass(queue.poll()); if (fragment == null || fragment.mFragmentClass == null) continue; Intent intent = new Intent(this, MainActivity.class); intent.setAction(Intent.ACTION_VIEW); intent.putExtra(INTENT_SECTION, fragment.mFragmentClass.getCanonicalName()); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); ShortcutInfo shortcut = new ShortcutInfo.Builder(this, fragment.mFragmentClass.getSimpleName()) .setShortLabel(getString(fragment.mId)) .setLongLabel(Utils.strFormat(getString(R.string.open), getString(fragment.mId))) .setIcon(Icon.createWithResource(this, fragment.mDrawable == 0 ? R.drawable.ic_blank : fragment.mDrawable)) .setIntent(intent) .build(); shortcutInfos.add(shortcut); } shortcutManager.setDynamicShortcuts(shortcutInfos); }