前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >android桌面快捷方式跳转到指定activity

android桌面快捷方式跳转到指定activity

作者头像
全栈程序员站长
发布2022-07-11 09:55:43
6520
发布2022-07-11 09:55:43
举报

大家好,又见面了,我是全栈君。

AndroidManifest.xml 应用主入口配置:

代码语言:javascript
复制
        <activity
            android:name="com.*.cust.contacts.MainActivity"
            android:exported="true"
            android:label="@string/app_name"
            android:screenOrientation="portrait" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <!-- 自己定义的action,通过自己定义的action能够应用内调用 -->
                <action android:name="*.intent.action.SHORTCUT" />

                <category android:name="android.intent.category.LAUNCHER" />
                <!-- 必须加上这个。否则无法直接使用自定的action -->
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>

创建快捷方式:

代码语言:javascript
复制
    // 自己定义action
    Intent intent = new Intent("*.intent.action.SHORTCUT");
    Bundle bundle = new Bundle();
    // 能够依据传递參数运行对应操作
    bundle.putString("needgoto", "*activity");
    intent.putExtras(bundle);
    // 创建桌面快捷方式
    Intent shortcutintent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
    // 是否同意反复创建
    shortcutintent.putExtra("duplicate", true);
    // 须要显示的名称
    shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.app_name_1));
    // 快捷图片
    Parcelable icon = Intent.ShortcutIconResource.fromContext(getApplicationContext(), R.drawable.ic_launcher);
    shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);
    // 点击快捷图片,运行的程序主入口
    shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, intent);
    // 发送广播运行操作
    sendBroadcast(shortcutintent);

发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/115203.html原文链接:https://javaforall.cn

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2022年2月7,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档