Java 静态快捷方式android don';不出现
我试图为我的应用程序添加快捷方式,但当我长时间单击时,我看不到它 我仔细检查了我的应用程序id和活动 这是我尝试的 My shortcut.xml:Java 静态快捷方式android don';不出现,java,android,android-studio,kotlin,android-shortcut,Java,Android,Android Studio,Kotlin,Android Shortcut,我试图为我的应用程序添加快捷方式,但当我长时间单击时,我看不到它 我仔细检查了我的应用程序id和活动 这是我尝试的 My shortcut.xml: <shortcut android:shortcutId="conso" android:enabled="true" android:icon="@drawable/ic_budgeting" android:shortcutShortLabel="@string/shortcut_conso_short
<shortcut
android:shortcutId="conso"
android:enabled="true"
android:icon="@drawable/ic_budgeting"
android:shortcutShortLabel="@string/shortcut_conso_short"
android:shortcutLongLabel="@string/shortcut_conso_long"
android:shortcutDisabledMessage="@string/shortcut_conso_dissable_message">
<intent
android:action="android.intent.action.VIEW"
android:targetPackage="com.****.stubs_dev.debug"
android:targetClass="com.******iviConsoActivity" />
<!-- If your shortcut is associated with multiple intents, include them
here. The last intent in the list determines what the user sees when
they launch this shortcut. -->
</shortcut>
我在舱单上添加在应用程序和活动中,我还添加了android:exported=“true” 我的代码怎么了 在这里编辑我的清单
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="****">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
<uses-permission android:name="android.permission.USE_BIOMETRIC" />
<uses-permission android:name="android.permission.USE_FINGERPRINT" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
/>
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:name="....."
android:icon="@mipmap/..."
android:label="@string/app_name"
android:networkSecurityConfig="@xml/network_security_config"
android:resizeableActivity="false"
android:supportsRtl="true"
android:theme="@style/AppTheme"
android:usesCleartextTraffic="true"
tools:replace="icon">
我的活动宣言:
<activity
android:name=".****onsoActivity"
android:screenOrientation="portrait"
android:exported="true"
android:theme="@style/AppTheme.NoActionBar"
>
<meta-data android:name="android.app.shortcuts"
android:resource="@xml/shortcuts" />
</activity>
确保您的xml名称为
shortcuts.xml
,然后确保将shortcuts.xml
添加到具有android.intent.action.MAIN
和android.intent.category.launcher
intent过滤器的启动器活动中。
让我们假设它是MainActivity
,那么它看起来是这样的
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data android:name="android.app.shortcuts"
android:resource="@xml/shortcuts" />
这就是shortcut.xml
的全部内容吗?它需要包装在
标记中。您是否可以将清单片段粘贴到添加快捷方式.xml
的位置?我刚刚发布了manifest@lyrjie我的原始文件中有,请仔细检查文件名是否为shortcuts.xml
,最后是s。在你的帖子中,它被称为shortcut.xml
我需要在android.intent.category.LAUNCHER活动中添加什么?我想我需要在我单击此项目shortcutNo时重定向到的活动中添加此元数据,只有处理Intent.ACTION\u main
ACTION和`Intent.CATEGORY\u LAUNCHER`类别的主活动才能有快捷方式。因为具有这些意图的活动对于启动器中的用户是可见的
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data android:name="android.app.shortcuts"
android:resource="@xml/shortcuts" />