这就是我所做的,它奏效了。
首选项.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 扩展而来的。