2011-05-21 60 views
0

我想在我的Android应用程序中创建一项功能,这将允许用户在Android市场上向我的应用程序分享链接,以便将其发送给他们。分享从PreferenceScreen发送的应用程序电子邮件

preferences.xml我创造了这个如下

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

     <intent android:action="" /> 

</PreferenceScreen> 

我不知道是什么目的要我把这里我我怎么处理它被点击共享应用程序时,在PreferenceScreen。我想打开电子邮件并预先填充主题和应用程序的Android Market链接。

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

回答

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扩展而来的。

+0

想必您在EXTRA_TEXT正文中包含应用的市场网址? – 2011-05-22 16:43:00

+0

那是正确的! – Aakash 2011-05-22 18:32:42

相关问题