How can i share image using pinterest sdk in android? - android

I have installed Pinterest SDK using pinterst developer site in my android studio project and register app in developers account.I can't find out sources that can share the images in developer console.how can I share image just like facebook and twitter using sdk?

I have shared image using below code.
private void shareOnPinterest() {
String sharingText = "Sharing Text";
String imageUrl = "Image Url";
String description = "Description";
String url = String.format(
"https://www.pinterest.com/pin/create/button/?url=%s&media=%s&description=%s",
urlEncode(sharingText), urlEncode(imageUrl), description);
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
filterByPackageName(getActivity(), intent, getString("com.pinterest"));
startActivity(intent);
} else {
Utils.displayDialog(getActivity(), getResources().getString(R.string.error_somthing_went_wrong));
}
}
Hope this will help you!

Related

intent share facebook - Android

I want to share an image from android activity to facebook messenger app which is already opened in my device and reside in recent tasks of the android device.
I am using the below code to share the image but it is opening a new activity in messenger 'share seperately' but I want to share it to the already opened chat.
String mimeType = "image/*";
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setPackage("com.facebook.orca");
intent.setType(mimeType);
intent.putExtra(Intent.EXTRA_STREAM, contentUri);
intent.putExtra(EXTRA_PROTOCOL_VERSION, PROTOCOL_VERSION);
intent.putExtra(EXTRA_APP_ID, YOUR_APP_ID);
activity.startActivityForResult(shareIntent, SHARE_TO_MESSENGER_REQUEST_CODE);
Facebook has restricted the text sharing over the post. It will either support a valid URL link sharing or Image Sharing. So I've posted the code which is referenced from https://stackoverflow.com/a/22994833/8331006
private void shareAppLinkViaFacebook(String urlToShare) {
try {
Intent intent1 = new Intent();
intent1.setClassName("com.facebook.katana", "com.facebook.katana.activity.composer.ImplicitShareIntentHandler");
intent1.setAction("android.intent.action.SEND");
intent1.setType("text/plain");
intent1.putExtra("android.intent.extra.TEXT", urlToShare);
startActivity(intent1);
} catch (Exception e) {
// If we failed (not native FB app installed), try share through SEND
String sharerUrl = "https://www.facebook.com/sharer/sharer.php?u=" + urlToShare;
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(sharerUrl));
startActivity(intent);
}
}

I can't share a text + link on facebook

Why I can't set a text when I'm sharing on facebook?
I have this code:
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("text/plain");
String str = "My Text\n" + "http://play.google.com/store/apps/details?id=com.google.android.apps.maps";
shareIntent.putExtra(Intent.EXTRA_TEXT, str);
List<ResolveInfo> matches = getPackageManager().queryIntentActivities(shareIntent, 0);
for (ResolveInfo info : matches) {
if (info.activityInfo.packageName.toLowerCase().contains("com.facebook.katana")) {
shareIntent.setPackage(info.activityInfo.packageName);
startActivity(shareIntent);
break;
}
}
And it works, but only the link appears. Anyone Knows what is wrong?
(I don't want to use Facebook SDK.)
Thanks
Bad facebook! :-(
This is impossible, Because of you don't want use Facebook SDK.
You have to use the actual official separate Facebook Android SDK in your project to get the full sharing functionality. Which is extra work.
Change your decision, then see this:
https://developers.facebook.com/docs/sharing/android
ShareDialog shareDialog;
FacebookSdk.sdkInitialize(getApplicationContext());
shareDialog = new ShareDialog(UserProfileActivity.this);
ShareLinkContent content1 = new ShareLinkContent.Builder()
.setContentUrl(Uri.parse("https://Your url"))
.setContentTitle("name of content")
.setContentDescription("description")
.setImageUrl(Uri.parse("img url"))
.build();
shareDialog.show(content1);

Android share intent for Pinterest not working

I am doing an android share intent for Pinterest but is not fully working. I am able to attach the image but I can't send text to the "description" field in the share window. I've tried different types (text/plain, image/*, image/png) and also tried the ACTION_SEND_MULTIPLE intent type but still no luck. Google chrome share intent works perfectly so I'm sure Pinterest supports this functionality. Here is my code:
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("*/*");
intent.putExtra(Intent.EXTRA_TEXT, text);
if(file != null) intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
intent.setClassName(packageName, name);
this.startActivity(intent);
Any idea? thanks!
I found a way to share to Pinterest with plain Android intents (without using the Pinterest SDK), with help from Pin It button developer docs.
Basically you just open an URL like this with Intent.ACTION_VIEW; the official Pinterest app kindly supports these URLs. (I've earlier used a very similar approach for sharing to Twitter.)
https://www.pinterest.com/pin/create/button/
?url=http%3A%2F%2Fwww.flickr.com%2Fphotos%2Fkentbrew%2F6851755809%2F
&media=http%3A%2F%2Ffarm8.staticflickr.com%2F7027%2F6851755809_df5b2051c9_z.jpg
&description=Next%20stop%3A%20Pinterest
And for smoother user experience, set the intent to open directly in Pinterest app, if installed.
A complete example:
String shareUrl = "https://stackoverflow.com/questions/27388056/";
String mediaUrl = "http://cdn.sstatic.net/stackexchange/img/logos/so/so-logo.png";
String description = "Pinterest sharing using Android intents"
String url = String.format(
"https://www.pinterest.com/pin/create/button/?url=%s&media=%s&description=%s",
urlEncode(shareUrl), urlEncode(mediaUrl), urlEncode(description));
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
filterByPackageName(context, intent, "com.pinterest");
context.startActivity(intent);
Util methods used above:
public static void filterByPackageName(Context context, Intent intent, String prefix) {
List<ResolveInfo> matches = context.getPackageManager().queryIntentActivities(intent, 0);
for (ResolveInfo info : matches) {
if (info.activityInfo.packageName.toLowerCase().startsWith(prefix)) {
intent.setPackage(info.activityInfo.packageName);
return;
}
}
}
public static String urlEncode(String s) {
try {
return URLEncoder.encode(s, "UTF-8");
}
catch (UnsupportedEncodingException e) {
Log.wtf("", "UTF-8 should always be supported", e);
return "";
}
}
This is the result on a Nexus 5 with Pinterest app installed:
And if Pinterest app is not installed, sharing works just fine via a browser too:
for some reason pinterest app doesn't comply to the standard (Intent.EXTRA_TEXT) so we have to add it separately
if(appInfo.activityInfo.packageName.contains("com.pinterest"){
shareIntent.putExtra("com.pinterest.EXTRA_DESCRIPTION","your description");
}
File imageFileToShare = new File(orgimagefilePath);
Uri uri = Uri.fromFile(imageFileToShare);
Intent sharePintrestIntent = new Intent(Intent.ACTION_SEND);
sharePintrestIntent.setPackage("com.pinterest");
sharePintrestIntent.putExtra("com.pinterest.EXTRA_DESCRIPTION", text);
sharePintrestIntent.putExtra(Intent.EXTRA_STREAM, uri);
sharePintrestIntent.setType("image/*");
startActivityForResult(sharePintrestIntent, PINTEREST);

Android Share intent - facebook

i want to share something with my friends. so i preferred android share intent.
i used,
Intent i=new Intent(android.content.Intent.ACTION_SEND);
i.setType("text/plain");
i.putExtra(android.content.Intent.EXTRA_TEXT, "my share text");
startActivity(Intent.createChooser(i, "share via"));
this showing a list of available apps like Facebook, Twitter, Gmail, Message, Skype.. e.t.c..
If i pressed a Twitter in the sense, the above text "my share text" showing in the tweet text box.
But if i select Facebook, the status message not showing.
i want to set the status message programatically.
how can i achieve this?
Facebook SDK has this bug, it's pretty annoying, I know. But if you set a link (and only a link) as "my share text", it will appear in the facebook share box.
I just built this code and it's working for me:
private void shareAppLinkViaFacebook() {
String urlToShare = "YOUR_URL";
try {
Intent intent1 = new Intent();
intent1.setClassName("com.facebook.katana", "com.facebook.katana.activity.composer.ImplicitShareIntentHandler");
intent1.setAction("android.intent.action.SEND");
intent1.setType("text/plain");
intent1.putExtra("android.intent.extra.TEXT", urlToShare);
startActivity(intent1);
} catch (Exception e) {
// If we failed (not native FB app installed), try share through SEND
Intent intent = new Intent(Intent.ACTION_SEND);
String sharerUrl = "https://www.facebook.com/sharer/sharer.php?u=" + urlToShare;
intent = new Intent(Intent.ACTION_VIEW, Uri.parse(sharerUrl));
startActivity(intent);
}
}
Facebook does not allow the pre populating of text in the status box like as twitter. But we can pass the text with url to the Facebook. And it appears below the status box. check below code.
NOTE : Use Facebook SDK to share [ Recommended ].
Native share through intent
Intent shareIntent= new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_TEXT, "http://www.google.com");
shareIntent.setType("text/plain");
shareIntent.setPackage("com.facebook.katana");
startActivity(shareIntent);
Share through Facebook SDK
ShareDialog shareDialog;
// Sharing in Facebook using the SDK
FacebookSdk.sdkInitialize(this);
shareDialog = new ShareDialog(this);
String title = "Demo Title";
String URL = "http://www.google.com";
ShareLinkContent linkContent = new ShareLinkContent.Builder()
.setContentTitle(title).setContentDescription(URL)
.setContentUrl(Uri.parse(URL)).build();
shareDialog.show(linkContent);
Check the link below for reference.
Link 1
Let me know for queries or clarification.

how to share a link to facebook, twitter and etc?

Firstly, My app's function is to read the article. When a user reads the article and he want to share the article to facebook or others, I cannot find link/ hyperlink from the type.
Here is my sharing function
private void shareIt() {
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
String shareBody = "Here is the share content body";
sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Subject Here");
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareBody);
startActivity(Intent.createChooser(sharingIntent, "Share via"));
}
The thing that i want is the share function when using computer to read the article and got the share button. In the sharing medium, it will appear as the content of the article instead of plain text.
So, how to edit the code so that i can share a link?
Do guide me on Manifest.xml, i am not sure interfilter need to add which category too.
Second, i saw the sharing list, the built-in list not so good for me because i want those those facebook, sina, twitter instead of google, gmail, bluetooth, line or messaging.
So, how to implement the list of sharing through java?
It could be like this
sharebtn = new Custom_ButtonField(share, shareactive, shareactive) {
protected boolean navigationClick(int status, int time) {
if (Config_GlobalFunction.isConnected()) {
String NEXT_URL = "http://www.facebook.com/connect/login_success.html";
String APPLICATION_ID = "153555168010272";
String APPLICATION_SECRET = "354f91a79c8fe5a8de9d65b55ef9aa1b";
String[] PERMISSIONS = Facebook.Permissions.USER_DATA_PERMISSIONS;
ApplicationSettings as = new ApplicationSettings(
NEXT_URL, APPLICATION_ID, APPLICATION_SECRET,
PERMISSIONS);
Facebook fb = Facebook.getInstance(as);
try {
User user = fb.getCurrentUser();
user.publishStatus(Config_GlobalFunction.sharelink
+ newsid);
} catch (FacebookException e) {
}
} else
Config_GlobalFunction.Message(
Config_GlobalFunction.nosharenews, 1);
return true;
}
};
add(sharebtn);
Precondition: you must import BB facebook sdk.

Categories

Resources