我决定考虑将静态快捷方式添加到应用程序中,使用此页面作为参考:
https://developer.android.com/preview/shortcuts.html https://developer.android.com/preview/shortcuts.html
我的快捷方式的 XML 目前如下所示:
<?xml version="1.0" encoding="utf-8"?>
<shortcuts xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android">
<shortcut
android:shortcutId="id"
android:enabled="true"
android:icon="@drawable/icon"
android:shortcutShortLabel="@string/short_label"
android:shortcutLongLabel="@string/long_label"
android:shortcutDisabledMessage="@string/disabled_message">
<intent
android:action="android.intent.action.VIEW"
android:targetPackage="com.example"
android:targetClass="com.example.Activity" />
<categories android:name="android.shortcut.category" />
</shortcut>
</shortcuts>
问题来自于targetClass
变量,因为我找不到启动方法Fragment
而不是一个Activity
。我想从快捷方式启动的大多数主页是Fragments
显示在一个Activity
。我怎样才能得到intent
直接启动到Fragment
反而?
您可以执行以下操作:
1) 在指定的意图中shortcuts.xml
,设置自定义意图操作字符串:
<intent
android:action="com.your.packagename.custom.name"
android:targetPackage="com.example"
android:targetClass="com.example.Activity" />
2) 检查getIntent().getAction()
对于指定的 Activity 中的意图操作android:targetClass
:
public void onCreate(Bundle savedInstanceState){
if (CUSTOM_NAME.equals(getIntent().getAction())) {
// do Fragment transactions here
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)