挑战练习:ShareCompat

来源:互联网 发布:lolita淘宝店 编辑:程序博客网 时间:2024/05/18 01:18

来自:android.support.v4.app.ShareCompat.IntentBuilder

IntentBuilder是一个用来构造ACTION_SEND和ACTION_SEND_MULTIPLE操作接口意图的辅助类,可实现intent共享,并使启动的activity实现内容共享,包括调用activity的Component名和包名。


挑战:在mReportButton的监听器中,改用ShareCompat.IntentBuilder来创建你的Intent


原码(CrimeFragment):

Intent i = new Intent(Intent.ACTION_SEND);i.setType("text/plain");i.putExtra(Intent.EXTRA_TEXT, getCrimeReport());i.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.crime_report_subject));i = Intent.createChooser(i, getString(R.string.send_report));startActivity(i);


使用ShareCompat替换:

ShareCompat.IntentBuilder sc = ShareCompat.IntentBuilder.from(getActivity());sc.setType("text/plain");sc.setText(getCrimeReport());       sc.setSubject(getString(R.string.crime_report_subject));sc.createChooserIntent();sc.startChooser();


1 0