The following is the first few sections of a chapter from The Busy Coder's Guide to Android Development, plus headings for the remaining major sections, to give you an idea about the content of the chapter.
Perhaps you would like to get your notes off of our book reader app and
into someplace else, or perhaps you would like to share them with somebody
else. Either way, we can do that using an
ACTION_SEND operation, to allow
the user to choose how to “send” the notes, such as sending them by email
or uploading them to some third-party note service.
To make this work, we will add a
ShareActionProvider to our action bar
This is a continuation of the work we did in the previous tutorial.
First, we need to allow the user to indicate that they want to “share” the
note displayed in the current
NoteFragment. By putting an action bar item
on the activity where the
NoteFragment is displayed, we do not need to
worry about letting the user choose which note to send — we simply send
whichever note they happen to be viewing or editing.
By using a
ShareActionProvider, the action item will handle most of the
work for allowing the user to choose where to send the note to. We only need
to provide an
Intent that identifies what is to be shared.
res/menu/notes.xml to add in the new
share toolbar button:
<?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http://schemas.android.com/apk/res/android"> <item android:id="@+id/share" android:actionProviderClass="android.widget.ShareActionProvider" android:showAsAction="ifRoom" android:title="@string/share"/> <item android:id="@+id/delete" android:icon="@drawable/ic_delete_white_24dp" android:showAsAction="ifRoom|withText" android:title="@string/delete"> </item> </menu>
Note that this menu definition requires a new string resource, named
with a value like
The preview of this section was stepped on by Godzilla.
The preview of this section is being chased by zombies.
The preview of this section is presently indisposed.