UFO ET IT

선호도에서 인 텐트에 추가 항목을 넣는 방법이 있습니까?

ufoet 2021. 1. 5. 08:26
반응형

선호도에서 인 텐트에 추가 항목을 넣는 방법이 있습니까?


안녕하세요, 환경 설정 화면에서 활동을 시작하고 있습니다. 활동은 세 가지 기본 설정간에 공유됩니다. 이 활동에 대한 추가 사항을 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();
    }
}

참조 URL : https://stackoverflow.com/questions/2082640/is-there-any-way-to-put-extras-to-intent-from-preferences

반응형