I got it to work. Thanks for the tip. I would recommend that for future versions of the book that you could provide a hint in the challenge to look at chapter 33 to see how permissions are checked, requested and results acted upon
Hello,could you help find the problem in the following code when I tried to finish the homework of ch15.5(about the usage of the ShareCompat.IntentBuilder class)
code:
mReportButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
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();
/* 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);
*/
}
});
The result:
When I tried to use the ShareCompat.IntentBuilder to replace the original code, I found that the system require you to reinstall the app in the first time you run it. After the app reinstalled, the page will automatically jump into the activity of sending email when I press the “add menu” in the crimelistactivity page, without any more operation.(Here, I supposed that it should jump into the page of crimepagerview activity and wait me to press the send-report button.)
You can paste the code provided above and run it to see the problem. Thank you.
I have solved the problem that located in carelessness that I have paste the new code twice in project and one of the copy is outside the mReportButton.setOnClickListener() method.