[英]Share the App email send from PreferenceScreen
我正在嘗試在我的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鏈接。
用戶將輸入電子郵件並將其發送給他們的朋友。
這是我做的,它的工作原理。
的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擴展而來的。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.