我已將Nougat快捷方式添加到我的Android應用程序,但所有快捷方式都希望啓動相同的活動,但使用不同的參數(然後,活動決定要添加哪個碎片)如何向清單聲明的意圖添加附加內容
所以,在res\xml-v25\shortcuts.xml
文件,我已經4種shortcut
元素描述,它們都具有相同的目的
<intent
android:action="android.intent.action.VIEW"
android:targetClass="com.example.MyActivity"
android:targetPackage="com.example"
/>
那麼,如何通過捆綁與演員該活動? 我試過<meta-data>
,<data>
,還有一件事,我忘了它是什麼,但onCreate
和onNewIntent
中的intent
總是空的。
<?xml version="1.0" encoding="utf-8"?>
<shortcuts xmlns:android="http://schemas.android.com/apk/res/android">
<shortcut
android:enabled="true"
android:icon="@drawable/feature_1"
android:shortcutId="feature_one"
android:shortcuDsaibledMessage="Disabled"
android:shortcutShrotLabel="Feature 1"
<intent
android:action="android.intent.action.VIEW"
android:targetClass="com.example.MyActivity"
android:targetPackage="com.example"
<!-- <extra -->
<!-- android:name="action" -->
<!-- android:value="feature_1"/> -->
</intent>
<shortcut>
// then 3 more shortcuts like this with feature 2, 3 and 4
不幸的是,當我在添加快捷'extra'的意圖時,當我長按圖標時,甚至不顯示快捷鍵。爲了證實這確實如此,我評論了'extra'部分並重新構建,並顯示出快捷方式。不知何故,android不想讓我通過額外的...我會嘗試與自定義類別 –
你可以發佈你的所有代碼? – venimania
我在我的應用程序中使用該代碼並且工作正常! – venimania