BILL LUAN: Shanghai GDG is a very
interesting developer community.
FEMALE SPEAKER: I'm glad somebody
has asked this question.
MALE SPEAKER: This is where the magic happens.
FEMALE SPEAKER: This is primarily a question and
answer show.
So if any of you out there would like to ask questions.
JENNY MURPHY: Hi everyone.
Welcome to this week's session of the Google+
Platform Office Hours.
Today, we're going to be pretending that we're on Mars,
and we're going to use the opportunity to explore sharing
from Android applications.
And before we dig into that though, let me introduce
myself and those around me, my co-hosts.
I'm Jennifer Murphy.
I'm a Developer Programs Engineer on the Google+
platform, which means I help you build cool stuff with our
APIs, plug-ins, and other things.
And joining me today is Julia.
JULIA FERRAIOLI: Hi, everyone.
I am Julia Ferraioli.
I am a Developer Advocate working mostly on
mobile these days.
And from behind the scenes until this moment, Chirag is
also joining us.
CHIRAG SHAH: I'm also most a Developer
Programs Engineer on mobile.
JENNY MURPHY: Thanks, Chirag.
You'll see his involvement in a few minutes.
So without further ado, what do you have to show us, Julia?
JULIA FERRAIOLI: So with all of the information going on
about Curiosity--
and I'm not talking about the one that killed the cat.
I'm talking about the one on Mars right now.
We thought it would be neat to build an application that let
Curiosity share to its other rover friends from its
application to Google+.
So we built an app that lets it do that.
We thought we'd let it do a couple things.
The first is simply sharing text and some links to cool
images or Google+ pages.
And the second is how it can actually direct those
particular share Intents, as we call
them, to Google+ itself.
And the third is to let it actually take pictures and
share those pictures into Google+.
JENNY MURPHY: Sounds really cool.
JULIA FERRAIOLI: Yeah.
OK, so should we look at some of the code
that lets this happen?
JENNY MURPHY: Yeah.
We love code here.
JULIA FERRAIOLI: I know.
OK, so the first thing that you'll see on
my code screen here--
this is [? emac's ?], is this import statement for importing
the ShareCompat class from the Android support library.
This is called ShareCompat.
This lets you easily build share Intents within your
application with pictures, text, and additionally, to, in
Google+, have attribution back to your application when the
item is posted.
So it's pretty cool.
So here you'll see a standard Android activity.
We call it Curiosity activity.
And down here, we have a one particular function that
basically shares an image from Curiosity.
We have a couple of arrays of strings in our resources files
that have links to images and some fun pre-specified
comments that you'll see a little bit later.
So the first thing we're going to do just to mix it up a
little bit is to select a comment and
image at random here.
So you can see that nice random number generator.
And then we're simply going to use the intent builder inside
of ShareCompat to build out our intent.
So this is where we're constructing our share intent.
And we're simply going to take that random comment and image
in the previous lines and set the text to
that particular comment.
So that will open up the share dialogue with the text
pre-filled as you set it.
Once we set the text type, in here it's just plain text, and
grab the intent from the share intent builder, we can fire
off the intent.
And we thought we'd show you what that
looks like in our app.
So Chirag is going to show you.
And as you can see, the application picker popped up.
He selected Google+, and was able to share an image that
popped up in the bottom as well.
OK, so the next thing we're going to do is show you how
you can effectively direct the share intent to a particular
application.
In our case, we're going to open up the Google+ app to
handle the intent.
So for that, we're just going to share the Google+ page.
So we're going to build the same sort of share intent
using the intent builder in ShareCompat.
We're going to get a string that says--
it talks about sharing the Google+ page, the
NASA Google+ page.
And then we're going to add in this line down here, called
setPackage.
And all we're doing is setting it to the Google+ application
package on the Android phone.
And this allows the share intent to be directed towards
the Google+ app.
So again, we're going to start the intent.
We're going to fire it off and show you what that
looks like as well.
So instead of going to the application picker, the
Google+ share dialogue opened up with the text and link
pre-specified there.
Now, you can also see that there is a nice preview of the
link included in the post.
There's a little picture as well as a description.
And that is drawn out of the link and into the post and
attached in a rich fashion.
So once he sends it off, it will be
shared into the stream.
Now, if you're looking at my stream or my posts, you'll see
that it also tells you that each post came from Curiosity,
I believe V1 and V2.
OK, so the last thing--
I mean, we need to let Curiosity take some pictures
and send them across to its rover friends, right?
So we will take a photo.
We'll let Curiosity take a photo and share it.
So here you see this method, takeAndSharePhoto.
We're simply going to let the app use the camera on my phone
to take the photo.
So we're going to open up a camera intent here.
We're going to tell it where to store the file after it
takes the photo.
And then instead of saying startActivity, we're actually
going to use startActivity for result so we can get the data
back from the camera.
OK.
So how do we actually construct the intent?
Well, if everything goes OK--
so Curiosity didn't cancel out of the image or anything--
we're going to go ahead and find the
file that was created.
And then we're going to essentially get the path to
the file and use it in the share intent.
We're also going to get a couple comments to pre-fill
some text as well.
So then, when we construct the share intent, again, we're
going to use the same intent builder.
But you'll see a couple extra things here.
In addition to setting the text, we're also going to set
the stream.
And here it is.
We're going to parse out the URI to the file that we took.
And we're going to set the type, instead of being text
plain, we're going to set it as an image jpeg.
Now, you could capture other types of media, such as
videos, and just set the type appropriately, and that would
be shared into Google+ as well.
So we're going to start it off the same as we did before,
setting the package and starting the activity.
Additionally, it's good practice to
clean up after yourself.
So we're going to delete the temp file as well.
If something should go wrong, we're going to just let them
know that we had some trouble connecting to Earth.
And we'll try again another time.
So Chirag, do you want to show us what that looks like?
JENNY MURPHY: That's a beautiful simulated martian
landscape we have there.
Where did we gather all that stuff?
JULIA FERRAIOLI: It was a combination of skill and
whatever was in the cubes around us.
JENNY MURPHY: I think I recognize the sand from one of
the cafes nearby.
JULIA FERRAIOLI: I think it's completely plausible.
JENNY MURPHY: I wonder if they'll miss it.
Hopefully not.
JULIA FERRAIOLI: Very life like.
Mars like.
So you can see the image that Chirag captured--
or Curiosity, rather, captured of the Martian landscape.
And once he clicks OK or the check mark, it will be added
to the post.
And you can see a preview attached to the post.
So once he shares it, it'll be shared in that nice rich
fashion that you see photos being shared on Google+ today,
nice and large, integrate altogether, all around
experience.
So that's how to share text, links, and media from your
Android application.
We think that Curiosity is going to have a really good
time with this.
JENNY MURPHY: Some pretty cool stuff.
So thanks a lot to Chirag for filling in the role of
Curiosity on there.
That was pretty cool.
JULIA FERRAIOLI: Yes.
How often can you say you acted the
part of a Mars rover?
JENNY MURPHY: That's very true.
So does Curiosity actually run Android OS?
JULIA FERRAIOLI: I don't know.
I don't think so.
But hopefully, maybe in the future.
JENNY MURPHY: It would be pretty cool.
Maybe a future rover will be green to match.
JULIA FERRAIOLI: Little Androids hopping around.
JENNY MURPHY: That would be pretty cool.
So this is an Office Hours show, so all of you out there
who are watching in the live stream, feel free to ask us
questions, either on the YouTube live stream--
Everyone, you may have noticed we just had a short blip.
But we're back.
And we're going to repeat the questions in case they didn't
make it to your screens.
So if you have any questions, please feel free to ask them
either on the YouTube live stream as a question, comment,
or on the Google+ event.
So if you have something in mind, please ask.
So starting with Nicolette.
Nicolette asks about all the Google messaging
services on her phone.
She has Google Voice, Google Talk, Google+ Messenger.
She likes them a lot.
But she's a little confused about so many of them, and she
wants them merged.
This is a great question or comment.
And on this show, we usually focus on the Google+ platform,
which means building software and applications that use
Google+ APIs and tools.
So this isn't something we're a great expert in, but we can
tell you how to get in touch with the right experts.
There's a send feedback tool that you can access on
plus.google.com.
You can also access it in your mobile Google+ application.
And that automatically routes your feedback, like this, to
the right team so that the right people can see it.
I'll be sharing a link to instructions on how to send
feedback in the show notes.
So grabbing the next question.
Oh yes, thanks very much for that feedback.
So Gerwin has a question.
Gerwin heard about Google Play services.
It was announced at Google I/O. It seems really cool.
What is it, and when did he start using it?
JULIA FERRAIOLI: So Google Play services, which we did
announce at I/O, is still coming soon.
We're really excited to get it out to you.
And as soon as is it's available for you to start
developing with, we will absolutely let you know.
However, what we've presented today was ShareCompat.
That's available for you to use basically right now.
So I'd recommend going out, getting the Support Library,
and start developing and incorporating that part into
your apps in the meanwhile.
JENNY MURPHY: Very cool.
So keep an eye on our blog and on our Google+ page.
Whenever we announce something, it shows up in both
those places.
And you will know right when everyone else does.
Probably right when we do.
So I'm going to poke around for some more questions.
And I don't actually see any other questions out.
development with Google+ today.
So thanks a lot to all of you who asked questions, and
thanks for tuning in.
JULIA FERRAIOLI: Thanks.
JENNY MURPHY: We're pretty much wrapping it up for this
week's session of the Google+ platform Office Hours.
So remember, we have them every week
with a different topic.
And we love to field your questions.
So always, always have them ready and in mind.
Thanks a lot.
Bye, everyone.
JULIA FERRAIOLI: Bye.