安卓shotcuts标签实现应用图标长按短按快捷键

2020-08-13  本文已影响0人  findTrueLoveByM

安卓shotcuts根标签实现点击桌面app图标快捷键功能

步骤1 在Manifest入口Activity标签下添加meta-data标签,在res xml目录下创建shotcuts.xml文件接着在meta-data里引用它


    android:allowBackup="true"

    android:icon="@mipmap/ic_launcher"

    android:label="@string/app_name"

    android:roundIcon="@mipmap/ic_launcher_round"

    android:supportsRtl="true"

    android:theme="@style/AppTheme"

    tools:ignore="GoogleAppIndexingWarning">

    <activity android:name=".MainActivity">

            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />

        <meta-data  android:name="android.app.shortcuts"

            android:resource="@xml/shotcuts"/>

    <activity android:name=".TwoActivity"/>

</application>

如上述文本所示,shotcut.xml里面内容如下

<?xml version="1.0" encoding="utf-8"?>

<shotcuts xmlns:android="http://schemas.android.com/apk/res/android">

            android:shortcutId="compose"

            android:enabled="true"

            android:icon="@mipmap/ic_launcher"

            android:shortcutShortLabel="@string/app_name1"

            android:shortcutLongLabel="@string/app_name2"

            android:shortcutDisabledMessage="@string/app_name3">

                android:action="android.intent.action.VIEW"

                android:targetPackage="com.example.maintest"

                android:targetClass="com.example.maintest.TwoActivity"/>

如果你的快捷方式与多个意图相关联,系统将在资源文件中启动与该快捷方式的最后一个意图相对应的活动,

并在后方堆栈中执行其他活动 。在这种情况下,当用户选择快捷方式然后按下后退键时,您的应用程序将启

动与资源文件中列出的快捷方式的倒数第二个意向对应的活动。这种行为模式会一直重复按下后退按钮,直

到用户清除快捷方式创建的后台堆栈。当用户下一次按下后退按钮时,系统将其导航回启动器。-->

            <categories android:name="android.shortcut.conversation"/>

</shotcuts>

添加shotcuts标签,在intent里注明添加要跳转的activity我的是activityTwo,这一步做完就可以实现点击app应用图标弹出快捷键跳转到指定的activity.

上一篇 下一篇

猜你喜欢

热点阅读