小さな Rss フィード アプリケーションを作成しました。このアプリケーションでは、リストビューで Rss を取得しています。リストビューの項目をクリックすると、Rss の詳細な説明を含む RssDetails.java アクティビティが開きます。このアクティビティでは、このアクティビティで共有の意図を実装しました。
RssDetails.java
super.onCreate(savedInstanceState);
setContentView(R.layout.details);
TextView detailsTitle = (TextView)findViewById(R.id.detailstitle);
TextView detailsDescription = (TextView)findViewById(R.id.detailsdescription);
TextView detailsPubdate = (TextView)findViewById(R.id.detailspubdate);
TextView detailsLink = (TextView)findViewById(R.id.detailslink);
findViewById(R.id.sharebutton).setOnClickListener(this);
Bundle bundle = this.getIntent().getExtras();
detailsTitle.setText(bundle.getString("keyTitle"));
detailsDescription.setText(bundle.getString("keyDescription"));
detailsPubdate.setText(bundle.getString("keyPubdate"));
detailsLink.setText(bundle.getString("keyLink"));}
@Override
public void onClick(View v) {
if (v.getId()==R.id.button1) {
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, "Hello World");
intent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Share via....play.google.com");
startActivity(Intent.createChooser(intent, "Share"));
}
}
共有ボタンをクリックすると、「Hello world」の代わりに Rss の説明が表示されるようになりました。これは R.id.detailsdescription から取得する必要があります。