Ale*_*voy 55 android intentfilter extras android-intent
嗨我正在从偏好设置屏幕启动活动.活动在三个偏好中共享.我想知道我是否可以在xml中为此活动设置额外内容
<Preference
android:key="action_1"
android:title="@string/action_1_title"
>
<intent
android:action="com.package.SHAREDACTION"
>
</intent>
</Preference>
Run Code Online (Sandbox Code Playgroud)
我想知道我能做些什么
<extras>
<item
android:name=""
android:value=""/>
</extras>
Run Code Online (Sandbox Code Playgroud)
我需要做的就是传递一个整数.我可以采取不同的行动并检查行动而不是额外的行动.
lud*_*igm 110
我得到了答案,你可以像这样使用它:
<Preference
android:key="xxx"
android:title="xxx"
android:summary="xxx">
<intent android:action="xxx" >
<extra android:name="xxx" android:value="xxx" />
</intent>
</Preference>
Run Code Online (Sandbox Code Playgroud)
小智 13
此处的文档中描述了一个意图数据字段.
它在API演示应用程序中用于XML首选项,以在Intent Preferences示例中启动intent.
相关示例来自preferences.xml中该演示的xml:
<PreferenceScreen
android:title="@string/title_intent_preference"
android:summary="@string/summary_intent_preference">
<intent android:action="android.intent.action.VIEW"
android:data="http://www.android.com" />
</PreferenceScreen>
Run Code Online (Sandbox Code Playgroud)
也许这种方法对你有用吗?
pat*_*oid 13
将首选项添加到preference.xml文件:
<Preference android:title="user" android:key="user"/>
Run Code Online (Sandbox Code Playgroud)
然后,您可以使用setOnPreferenceClickListener来启动带有额外内容的Intent.
Preference userButton = (Preference) findPreference("user");
userButton.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference arg0) {
Intent intent = new Intent(getActivity(), YourTargetActivity.class);
intent.putExtra(EXTRA, mUser);
startActivity(intent);
return true;
}
});
Run Code Online (Sandbox Code Playgroud)
Gau*_*tam 11
为我工作.
<shortcut
android:enabled="true"
android:icon="@mipmap/xxx"
android:shortcutDisabledMessage="@string/xxx"
android:shortcutId="xxxx"
android:shortcutLongLabel="xxx"
android:shortcutShortLabel="xxx">
<intent
android:action="android.intent.action.VIEW"
android:targetClass="xxx"
android:targetPackage="xxx">
<extra
android:name="intent_name"
android:value="true" />
</intent>
</shortcut>
Run Code Online (Sandbox Code Playgroud)
由于你的额外内容不是常量,你应该在java代码而不是xml中传递它们.
Intent intent = new Intent( this, YourTargetActivity.class );
intent.putExtra( EXTRAS_KEY, extras );
yourPref.setIntent( intent );
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
34455 次 |
最近记录: |