선호도에서 인 텐트에 추가 항목을 넣는 방법이 있습니까?
안녕하세요, 환경 설정 화면에서 활동을 시작하고 있습니다. 활동은 세 가지 기본 설정간에 공유됩니다. 이 활동에 대한 추가 사항을 xml로 설정할 수 있는지 궁금합니다.
<Preference
android:key="action_1"
android:title="@string/action_1_title"
>
<intent
android:action="com.package.SHAREDACTION"
>
</intent>
</Preference>
내가 뭔가 할 수 있는지 궁금해
<extras>
<item
android:name=""
android:value=""/>
</extras>
정말로 정수를 전달하기 위해해야 할 모든 것. 나는 다른 행동을 할 수 있고 엑스트라 대신 행동을 확인할 수 있습니다.
엑스트라는 상수가 아니므로 xml 대신 자바 코드로 전달해야합니다.
Intent intent = new Intent( this, YourTargetActivity.class );
intent.putExtra( EXTRAS_KEY, extras );
yourPref.setIntent( intent );
대답을 얻었습니다. 다음과 같이 사용할 수 있습니다.
<Preference
android:key="xxx"
android:title="xxx"
android:summary="xxx">
<intent android:action="xxx" >
<extra android:name="xxx" android:value="xxx" />
</intent>
</Preference>
preferences.xml 파일에 환경 설정을 추가하십시오.
<Preference android:title="user" android:key="user"/>
그런 다음 setOnPreferenceClickListener를 사용하여 추가로 인 텐트를 시작할 수 있습니다.
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;
}
});
여기 문서에 설명 된 의도에 대한 데이터 필드가 있습니다 .
인 텐트 기본 설정 예제에서 인 텐트를 시작하기 위해 XML 기본 설정에 대한 API 데모 애플리케이션에서 사용됩니다.
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>
이 접근 방식이 효과가있을 수 있습니까?
나를 위해 일하고 있습니다.
<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>
시장에서 이메일이나 요금을 보내려면 다음과 같은 것을 사용해야합니다.
<Preference
android:title="@string/title_intent_preference"
android:summary="@string/summary_intent_preference">
<intent android:action="android.intent.action.VIEW"
android:data="market://details?id=com.your_package" />
</Preference>
<Preference
android:title="@string/title_intent_preference"
android:summary="@string/summary_intent_preference">
<intent android:action="android.intent.action.VIEW"
android:data="mailto:your_email@gmail.com" />
</Preference>
당신이 사용할 수있는
<PreferenceScreen
android:title="@string/title_intent_preference"
android:summary="@string/summary_intent_preference">
<intent android:action="android.intent.action.VIEW"
android:data="hello world" />
</PreferenceScreen>
인 텐트 데이터를 보냅니다. 그런 다음 활동에서 다음을 사용하십시오.
getIntent().getDataString()
귀하의 질문에 대한 답변은 아니지만 매우 관련이 있습니다. 누군가가 유용하다고 생각할 수도 있습니다. 최신 API (> 11)의 경우 기본 설정 헤더 파일이 있으며 헤더 중 하나에 대한 사용자 지정 인 텐트를 정의 할 수 있습니다. 헤더 중 하나에 사용자 지정 Extra를 추가하려고했는데 찾은 솔루션은 다음과 같습니다.
preferences-headers.xml에서 :
<header
android:fragment="com.mypackage.MyPreference$Prefs1Fragment"
android:title="Intent"
android:summary="Launches an Intent.">
</header>
"MyPreference"클래스 (PreferenceActivity 확장)에는 다음이 있습니다.
public static class Prefs1Fragment extends PreferenceFragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = new Intent(getActivity(), MyTargetActivity.class);
// set the desired extras, flags etc to the intent
intent.putExtra("customExtra", "Something that I used to know");
// starting our target activity
startActivity(intent);
// ending the current activity, which is just a redirector to our end goal
getActivity().finish();
}
}
'UFO ET IT' 카테고리의 다른 글
Windows 배치 스크립트에서 따옴표 처리 (0) | 2021.01.05 |
---|---|
Ruby에서 float의 표시 정밀도 설정 (0) | 2021.01.05 |
MD5와 같은 해시 함수는 어떻게 고유합니까? (0) | 2021.01.05 |
Scala에서 더 나은 문자열 포맷팅 (0) | 2021.01.05 |
관계형 대수로 MAX를 어떻게 찾을 수 있습니까? (0) | 2021.01.05 |