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 Market 链接预先填充它。

用户将输入电子邮件并将其发送给他们的朋友。

4

1 回答 1

2

这就是我所做的,它奏效了。

首选项.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 回答