android.support.v4.content.pm.ShortcutManagerCompat Java Examples

The following examples show how to use android.support.v4.content.pm.ShortcutManagerCompat. 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: ShareUtil.java    From memetastic with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Try to create a new desktop shortcut on the launcher. Add permissions:
 * <uses-permission android:name="android.permission.INSTALL_SHORTCUT" />
 * <uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
 *
 * @param intent  The intent to be invoked on tap
 * @param iconRes Icon resource for the item
 * @param title   Title of the item
 */
public void createLauncherDesktopShortcut(final Intent intent, @DrawableRes final int iconRes, final String title) {
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    if (intent.getAction() == null) {
        intent.setAction(Intent.ACTION_VIEW);
    }

    ShortcutInfoCompat shortcut = new ShortcutInfoCompat.Builder(_context, Long.toString(new Random().nextLong()))
            .setIntent(intent)
            .setIcon(IconCompat.createWithResource(_context, iconRes))
            .setShortLabel(title)
            .setLongLabel(title)
            .build();
    ShortcutManagerCompat.requestPinShortcut(_context, shortcut, null);
}
 
Example #2
Source File: ShareUtil.java    From openlauncher with Apache License 2.0 6 votes vote down vote up
/**
 * Try to create a new desktop shortcut on the launcher. Add permissions:
 * <uses-permission android:name="android.permission.INSTALL_SHORTCUT" />
 * <uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
 *
 * @param intent  The intent to be invoked on tap
 * @param iconRes Icon resource for the item
 * @param title   Title of the item
 */
public void createLauncherDesktopShortcut(final Intent intent, @DrawableRes final int iconRes, final String title) {
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    if (intent.getAction() == null) {
        intent.setAction(Intent.ACTION_VIEW);
    }

    ShortcutInfoCompat shortcut = new ShortcutInfoCompat.Builder(_context, Long.toString(new Random().nextLong()))
            .setIntent(intent)
            .setIcon(IconCompat.createWithResource(_context, iconRes))
            .setShortLabel(title)
            .setLongLabel(title)
            .build();
    ShortcutManagerCompat.requestPinShortcut(_context, shortcut, null);
}
 
Example #3
Source File: ShareUtil.java    From Stringlate with MIT License 6 votes vote down vote up
/**
 * Try to create a new desktop shortcut on the launcher. Add permissions:
 * <uses-permission android:name="android.permission.INSTALL_SHORTCUT" />
 * <uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
 *
 * @param intent  The intent to be invoked on tap
 * @param iconRes Icon resource for the item
 * @param title   Title of the item
 */
public void createLauncherDesktopShortcut(Intent intent, @DrawableRes int iconRes, String title) {
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    if (intent.getAction() == null) {
        intent.setAction(Intent.ACTION_VIEW);
    }

    ShortcutInfoCompat shortcut = new ShortcutInfoCompat.Builder(_context, Long.toString(new Random().nextLong()))
            .setIntent(intent)
            .setIcon(IconCompat.createWithResource(_context, iconRes))
            .setShortLabel(title)
            .setLongLabel(title)
            .build();
    ShortcutManagerCompat.requestPinShortcut(_context, shortcut, null);
}
 
Example #4
Source File: AppShortcutsHelper.java    From rcloneExplorer with MIT License 5 votes vote down vote up
public static void addRemoteToHomeScreen(Context context, RemoteItem remoteItem) {
    String id = getUniqueIdFromString(remoteItem.getName());

    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());

    ShortcutInfoCompat shortcutInfo = new ShortcutInfoCompat.Builder(context, id)
            .setShortLabel(remoteItem.getName())
            .setIcon(IconCompat.createWithResource(context, AppShortcutsHelper.getRemoteIcon(remoteItem.getType(), remoteItem.isCrypt())))
            .setIntent(intent)
            .build();

    ShortcutManagerCompat.requestPinShortcut(context, shortcutInfo, null);
}
 
Example #5
Source File: ShortcutsPlugin.java    From cordova-plugin-shortcuts-android with MIT License 5 votes vote down vote up
private boolean addPinnedShortcut(
    JSONArray args
) throws PackageManager.NameNotFoundException, JSONException {
    ShortcutInfoCompat shortcut = buildPinnedShortcut(args.optJSONObject(0));
    Context context = this.cordova.getActivity().getApplicationContext();
    return ShortcutManagerCompat.requestPinShortcut(context, shortcut, null);
}
 
Example #6
Source File: AppShortcutsHelper.java    From rcloneExplorer with MIT License 4 votes vote down vote up
public static boolean isRequestPinShortcutSupported(Context context) {
    return ShortcutManagerCompat.isRequestPinShortcutSupported(context);
}
 
Example #7
Source File: ShortcutsPlugin.java    From cordova-plugin-shortcuts-android with MIT License 4 votes vote down vote up
private boolean supportsPinned() {
    Context context = this.cordova.getActivity().getApplicationContext();
    return ShortcutManagerCompat.isRequestPinShortcutSupported(context);
}