Issue
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);
Solution
Thats an example from my code, but if you want some reference material tap on the hyperlink for an article.
public void shareText(String text) {
String mimeType = "text/plain";
String title = "Example title";
Intent shareIntent = ShareCompat.IntentBuilder.from(this)
.setType(mimeType)
.setText(text)
.getIntent();
if (shareIntent.resolveActivity(getPackageManager()) != null){
startActivity(shareIntent);
}
}
Blog post on ShareCompat.IntentBuilder and sharing intents
Answered By - klenki
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.