0

私は自分のAndroidアプリに機能を作成しようとしています。これにより、ユーザーはAndroidマーケットで自分のアプリへのリンクを、メールを送信したい人と共有できます。

私はこれpreferences.xmlを以下のように作成しました

<PreferenceScreen
            android:title="Share the App" 
            android:summary="Share the App with your friends.">

        <intent android:action="" />

</PreferenceScreen>

ここにどのような意図を置くべきか、[アプリの共有]をクリックしたときにどのように処理するのかわかりませんPreferenceScreen。メールを開いて、件名とアプリのAndroidマーケットリンクを件名に事前入力したいと思います。

ユーザーはメールアドレスを入力して友達に送信します。

4

1 に答える 1

2

これが私がしたことであり、それはうまくいきました。

Preferences.xml

<PreferenceScreen
            android:title="Share the App" 
            android:summary="Share the App with your Friends.">

        <intent android:action="myapp.action.SHARE_APP" />

</PreferenceScreen>

次に、これをAndroidManifest.xmlに追加しました

<activity android:name=".ShareApp"
      android:theme="@style/Theme.MyApp">
      <intent-filter>
        <action android:name="myapp.action.SHARE_APP" />
        <category android:name="android.intent.category.DEFAULT"/>                      
      </intent-filter>
</activity>

次に、ShareApp.javaを作成し、ここにコードを追加しました。

public class ShareApp extends UrSettings {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
        emailIntent.setType("text/plain"); 
        emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Hey there! Cheers!");
        emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Try MyApp!"); 
        startActivity(emailIntent);  
        super.onCreate(savedInstanceState);
    }
}

そして、それはうまくいきました!ちなみに、UrSettingsクラスはPreferenceActivityから拡張されています。

于 2011-05-21T23:28:13.923 に答える