user167698 user167698 - 1 year ago 170
Android Question

How to startActivity with a ShareCompat.IntentBuilder

I'm attempting to add a shared intent to post to Google Plus and can't seem to resolve the issue of passing the new

ShareCompat.IntentBuilder
(Android support library class) to the
startActivity
method. I'm started out using this example. My app is compiled using Android 2.2 platform. Is it possible that there is another supporting way to start the Activity to launch the shared intent.

IntentBuilder shareIntent = ShareCompat.IntentBuilder.from(MyActivity.this);
shareIntent.setText(message);
shareIntent.setSubject(subject);

if (mFullFileName != null) {
File imageFile = new File(mFullFileName);
if (imageFile.exists()) {
shareIntent.setStream(Uri.fromFile(imageFile));
shareIntent.setType("image/jpeg");
}
} else {
shareIntent.setType("*.*");
}
shareIntent.getIntent();
// doesn't compile only accepts Intent and not the Intentbuilder
startActivity(shareIntent);

Answer Source

Funny, I just figured it out... the example given was suppose create an Intent and not an IntentBuilder object.. had to change my code to chain the object creation.

Intent i = ShareCompat.IntentBuilder.from(MyActivity.this)
                       .setText(message)
                       .setSubject(subject)
                       .setStream(Uri.fromFile(imageFile))
                       .setType("image/jpeg")
                       .getIntent()
                       .setPackage("com.google.android.apps.plus");
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download