android创建桌面快捷方式

android 共支持三种快捷方式,

  • 静态快捷方式
  • 动态快捷方式
  • 固定快捷方式
    如果要把快捷方式创建到桌面 需要创建固定快捷方式 【官方文档

代码如下:

ShortcutManager shortcutManager =
        context.getSystemService(ShortcutManager.class);

if (shortcutManager.isRequestPinShortcutSupported()) {
    // Assumes there's already a shortcut with the ID "my-shortcut".
    // The shortcut must be enabled.
    ShortcutInfo pinShortcutInfo =
            new ShortcutInfo.Builder(context, "my-shortcut").build();

    // Create the PendingIntent object only if your app needs to be notified
    // that the user allowed the shortcut to be pinned. Note that, if the
    // pinning operation fails, your app isn't notified. We assume here that the
    // app has implemented a method called createShortcutResultIntent() that
    // returns a broadcast intent.
    Intent pinnedShortcutCallbackIntent =
            shortcutManager.createShortcutResultIntent(pinShortcutInfo);

    // Configure the intent so that your app's broadcast receiver gets
    // the callback successfully.For details, see PendingIntent.getBroadcast().
    PendingIntent successCallback = PendingIntent.getBroadcast(context, /* request code */ 0,
            pinnedShortcutCallbackIntent, /* flags */ 0);

    shortcutManager.requestPinShortcut(pinShortcutInfo,
            successCallback.getIntentSender());
}

如果创建的时候报这个错

Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified

修改这行代码

 PendingIntent successCallback = PendingIntent.getBroadcast(context, /* request code */ 0,
            pinnedShortcutCallbackIntent, /* flags */ 0);

PendingIntent successCallback = PendingIntent.getBroadcast(this, /* request code */ 0,
                    pinnedShortcutCallbackIntent, /* flags */ PendingIntent.FLAG_IMMUTABLE);
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在Ubuntu中创建桌面快捷方式非常简单,可以帮助你快速访问常用的程序或文件夹。以下是步骤: 1. 打开Unity桌面(对于旧版本的Ubuntu,使用Unity接口;新版本如GNOME,过程类似)。 2. 在桌面上,找到你想添加快捷方式的位置,通常是左上角的【应用程序】区域,或者点击【 Activities 】搜索框旁边的“+”图标。 3. **通过搜索添加快捷方式**:在搜索框中输入你要创建快捷方式的程序名称,比如"Google Chrome"。然后,在搜索结果中找到该程序,鼠标右键点击它,选择“创建快捷方式桌面”。 4. **通过文件夹直接拖拽**:如果你有一个文件夹,可以直接将其拖放到桌面上。右键点击文件夹,选择“创建快捷方式”。 5. **手动创建文本快捷方式**:如果需要为自定义命令创建快捷方式,可以右键点击桌面空白处,选择“创建快捷方式”,然后在打开的对话框中输入`bash` 或 `gnome-terminal`(取决于你的系统)前缀,加上你的命令路径,例如 `gnome-terminal --command="cd /path/to/your/command"`。 6. **命名和个性化**:为快捷方式添加一个有意义的名字,方便识别。完成之后,你可以通过双击它来启动相应的程序或执行命令。 相关问题: 1. 如何为非安装程序创建桌面快捷方式? 2. Ubuntu的Unity桌面是否已经过时,现在应该用什么替代? 3. 如果我想在快捷方式上设置开机启动,怎么做?

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值