Image could not be loaded on twitter - android

I'm trying to share an image through twitter everything worked fine with facebook but twitter the image could not be loaded! I dont know why here is my code:
enter code here
public void share(String nameApp)
{
try
{
List<Intent> targetedShareIntents = new ArrayList<Intent>();
Intent share = new Intent(android.content.Intent.ACTION_SEND);
share.setType("image/jpg");
List<ResolveInfo> resInfo = getPackageManager().queryIntentActivities(share, 0);
if (!resInfo.isEmpty())
{
for (ResolveInfo info : resInfo)
{
Intent targetedShare = new Intent(android.content.Intent.ACTION_SEND);
targetedShare.setType("image/jpg"); // put here your mime type
if (info.activityInfo.packageName.toLowerCase().contains(nameApp) || info.activityInfo.name.toLowerCase().contains(nameApp)) {
targetedShare.putExtra(Intent.EXTRA_SUBJECT, "Sample Photo");
targetedShare.putExtra(Intent.EXTRA_TEXT,"This photo is created by Me");
ClassGlobal.selectedPagerURLs = new String[ClassGlobal.selectedAlbum.album_Thumbnail_Images.size()];
//This path worked fine with facebook sdk but in twitter everything is fine except the image could not be loaded
Uri screenshotUri = Uri.parse(ClassGlobal.selectedPagerURLs[currentItem]=ClassGlobal.selectedAlbum.album_Thumbnail_Images.get(currentItem).thumbnail_Url);
targetedShare.putExtra(Intent.EXTRA_STREAM,screenshotUri);
targetedShare.setPackage(info.activityInfo.packageName);
targetedShareIntents.add(targetedShare);
}
}
Intent chooserIntent = Intent.createChooser(targetedShareIntents.remove(0), "Select app to share");
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, targetedShareIntents.toArray(new Parcelable[]{}));
startActivity(chooserIntent);
}
}
catch(Exception e)
{
Log.v("VM","Exception while sending image on" + nameApp + " "+ e.getMessage());
}
}
Any help would be appreciated Thank you

It seems to be a bug on the twitter app. I get the same error when trying to share an image from Gallery to Twitter on my Nexus 4 with Android 4.3. Weirdly enough, this worked on 4.2.2 before I ota upgraded today.

Uri imagePathUri = Uri.parse("android.resource://com.example.test.social_integration/"+R.drawable.share);
Bitmap b = BitmapFactory.decodeResource(getResources(), R.drawable.share);
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
b.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
String path = MediaStore.Images.Media.insertImage(getContentResolver(), b, "Title", null);
Uri imageUri = Uri.parse(path);
Intent shareIntent = new Intent();
shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_TEXT, "Test_Tweet");
shareIntent.putExtra(Intent.EXTRA_STREAM, imageUri);
shareIntent.setType("image/jpeg");
PackageManager pm = v.getContext().getPackageManager();
List<ResolveInfo> activityList = pm.queryIntentActivities(shareIntent, 0);
for (final ResolveInfo app : activityList)
{
if (app.activityInfo.name.contains("twitter"))
{
final ActivityInfo activity = app.activityInfo;
final ComponentName name = new ComponentName(activity.applicationInfo.packageName, activity.name);
shareIntent.addCategory(Intent.CATEGORY_LAUNCHER);
shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
shareIntent.setComponent(name);
v.getContext().startActivity(shareIntent);
break;
}
}
}

Related

Default Messaging App version 4.2.1 is not able show in intent chooser dialog with other apps like whatsapp, etc

I want to show only Messaging app and Whatsapp application in Intentchooser. The following code is working fine with some other devices like moto e, g, etc.. But in some other devices its now showing the default messaging application. This is my code. Please help me.
private void shareTheApp() {
Resources resources = getResources();
Intent emailIntent = new Intent();
emailIntent.setAction(Intent.ACTION_SEND);
PackageManager pm = getPackageManager();
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.setType("text/plain");
List<ResolveInfo> resInfo = pm.queryIntentActivities(sendIntent, 0);
List<LabeledIntent> intentList = new ArrayList<LabeledIntent>();
for (int i = 0; i < resInfo.size(); i++) {
// Extract the label, append it, and repackage it in a LabeledIntent
ResolveInfo ri = resInfo.get(i);
String packageName = ri.activityInfo.packageName;
emailIntent.setAction(Intent.ACTION_SEND);
emailIntent.setType("text/plain");
if (packageName.contains("com.whatsapp")) {
emailIntent.putExtra(Intent.EXTRA_TEXT, resources.getString(R.string.share_text));
emailIntent.setType("text/plain");
emailIntent.setPackage(packageName);
}
if (packageName.contains("mms")) {
isMmsAvailable = true;
Intent intent = new Intent();
intent.setComponent(new ComponentName(packageName, ri.activityInfo.name));
intent.setAction(Intent.ACTION_SEND);
intent.setType("text/plain");
if (packageName.contains("mms")) {
intent.putExtra(Intent.EXTRA_TEXT, resources.getString(R.string.share_text));
}
intentList.add(new LabeledIntent(intent, packageName, ri.loadLabel(pm), ri.icon));
}
}
if(!isMmsAvailable) {
isMmsAvailable = false;
Intent smsIntent = new Intent(Intent.ACTION_VIEW);
smsIntent.setData(Uri.parse("sms:"));
smsIntent.putExtra("sms_body", resources.getString(R.string.share_text));
intentList.add(new LabeledIntent(smsIntent, "", "Messaging", R.drawable.ic_launcher));
}
// convert intentList to array
LabeledIntent[] extraIntents = intentList.toArray(new LabeledIntent[intentList.size()]);
Intent openInChooser = Intent.createChooser(emailIntent, getResources().getString(R.string.openchooser_tittle));
openInChooser.addCategory(Intent.CATEGORY_DEFAULT);
openInChooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, extraIntents);
startActivity(openInChooser);
}
Yes, I solved this problem :) below the code.
Resources resources = getResources();
List<Intent> selectedIntents = new ArrayList<Intent>();
Intent shareIntent=new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.setType("text/plain");
List<ResolveInfo> resInfos=getPackageManager().queryIntentActivities(shareIntent, 0);
if(!resInfos.isEmpty()){
for(ResolveInfo resInfo : resInfos) {
String packageName=resInfo.activityInfo.packageName;
if(packageName.contains("com.whatsapp")){
Intent intent=new Intent();
intent.setComponent(new ComponentName(packageName, resInfo.activityInfo.name));
intent.setAction(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, resources.getString(R.string.share_text));
intent.setPackage(packageName);
selectedIntents.add(intent);
}
}
Intent sendIntent = new Intent(Intent.ACTION_VIEW);
sendIntent.setType("vnd.android-dir/mms-sms");
List<ResolveInfo> resInfo = getPackageManager().queryIntentActivities(sendIntent, 0);
for (int i = 0; i < resInfo.size(); i++) {
// Extract the label, append it, and repackage it in a LabeledIntent
ResolveInfo ri = resInfo.get(i);
String packageName = ri.activityInfo.packageName;
if (packageName.contains("mms")) {
Intent intent = new Intent();
intent.setComponent(new ComponentName(packageName, ri.activityInfo.name));
intent.setAction(Intent.ACTION_SEND);
intent.setType("text/plain");
if (packageName.contains("mms")) {
intent.putExtra(Intent.EXTRA_TEXT, resources.getString(R.string.share_text));
selectedIntents.add(intent);
}
}
}
if(!selectedIntents.isEmpty()){
Intent chooserIntent = null;
chooserIntent = Intent.createChooser(selectedIntents.get(0), resources.getString(R.string.openchooser_tittle));
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, selectedIntents.toArray(new Parcelable[]{}));
startActivity(chooserIntent);
}
}
we need to call both action ACTION_SEND and ACTION_VIEW. Now it will show in intent chooser for both type of messaging app. Hope it might be usefull for some else.

Sharing images in other application

I have application with images and I want share image which is choosen by user in some other application. From other question here I know that I must put the image in public place so it can be accesed by other application. But I still get error "no application can perform this action" any idea where am I doing mistake?
Code for copying image to SD card:
String path = Environment.getExternalStorageDirectory().toString();
File file = new File(path,String.valueOf(idOfImage));
if (!file.exists())
{
Bitmap myBitmap = BitmapFactory.decodeResource(getResources(),idOfImage);
FileOutputStream out = null;
try {
out = new FileOutputStream(file);
myBitmap.compress(Bitmap.CompressFormat.PNG, 90, out);
} catch (Exception e)
{
e.printStackTrace();
} finally {
try {
if (out != null)
{
out.close();
}
} catch (IOException e)
{
e.printStackTrace();
}
}
Code for sending the intent and picking chooser:
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
Uri uri = Uri.fromFile(file);
shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
StartActivity(Intent.createChooser(shareIntent,getResources().getText(R.string.share)));
Thanks for answers.
EDIT: Works fine when sharingIntent.setType("image/png"); lane added, with Gmail and G+ , but doesnt work with Messengers FB and others.
try this code
Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setType("image/*");
shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, (String)
v.getTag(R.string.app_name));
shareIntent.putExtra(Intent.EXTRA_STREAM, imageUri); // put your image URI
PackageManager pm = v.getContext().getPackageManager();
List<ResolveInfo> activityList = pm.queryIntentActivities(shareIntent, 0);
for (final ResolveInfo app : activityList)
{
if ((app.activityInfo.name).contains("facebook"))
{
final ActivityInfo activity = app.activityInfo;
final ComponentName name = new ComponentName(activity.applicationInfo.packageName, activity.name);
shareIntent.addCategory(Intent.CATEGORY_LAUNCHER);
shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
shareIntent.setComponent(name);
v.getContext().startActivity(shareIntent);
break;
}
}
Edit 1
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM,Uri.fromFile(new File(filePath))); //optional//use this when you want to send an image
shareIntent.setType("image/jpeg");
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(Intent.createChooser(shareIntent, "send"));
use this code i tried it and it works here at my side
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
Uri screenshotUri = Uri.parse(path);
sharingIntent.setType("image/png");
sharingIntent.putExtra(Intent.EXTRA_STREAM, screenshotUri);
startActivity(Intent.createChooser(sharingIntent, "Share image using"));

how can PutExtra EXTRA_EMAIL for Action_send?

I have code that filter specific apps for ACTION_SEND intent.
But I can not set for gmail and mail EXTRA_EMAIL.
I try for this:
String packageName = ri.activityInfo.packageName;
if(packageName.contains("email"))
{
emailIntent.setPackage(packageName);
}
else if( packageName.contains("android.gm") || packageName.contains("mail"))
{
Intent intent = new Intent();
intent.setComponent(new ComponentName(packageName, ri.activityInfo.name));
intent.setAction(Intent.ACTION_SEND);
intent.setType("text/plain");
if(packageName.contains("android.gm")) {
intent.putExtra(Intent.EXTRA_SUBJECT, resources.getString(R.string.share_email_subject));
intent.putExtra(Intent.EXTRA_EMAIL,"boghche.app#gmail.com");
The EXTRA_EMAIL extra requires an array of String. Use the String Array constructor
Intent.putExtra(android.content.Intent.EXTRA_EMAIL,new String[] { "boghche.app#gmail.com" });
You need to check this way.
Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "urSubject");
shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, "ExtraText");
PackageManager pm = v.getContext().getPackageManager();
List<ResolveInfo> activityList = pm.queryIntentActivities(shareIntent, 0);
for (final ResolveInfo app : activityList)
{
if ((app.activityInfo.name).contains("gmail"))
{
final ActivityInfo activity = app.activityInfo;
final ComponentName name = new ComponentName(activity.applicationInfo.packageName, activity.name);
shareIntent.addCategory(Intent.CATEGORY_LAUNCHER);
shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
shareIntent.setComponent(name);
v.getContext().startActivity(shareIntent);
break;
}
}
final Intent intent = new Intent(
android.content.Intent.ACTION_SEND);
intent.setType("*/*");
intent.putExtra(android.content.Intent.EXTRA_SUBJECT,
"subject name");
intent.putExtra(android.content.Intent.EXTRA_STREAM,
Uri.fromFile(new File(file.toString())));
final PackageManager pm = getPackageManager();
final List<ResolveInfo> matches = pm.queryIntentActivities(
intent, 0);
ResolveInfo best = null;
for (final ResolveInfo info : matches)
if (info.activityInfo.packageName.endsWith(".gm")
|| info.activityInfo.name.toLowerCase()
.contains("gmail"))
best = info;
if (best != null)
intent.setClassName(best.activityInfo.packageName,
best.activityInfo.name);
startActivity(intent);

Customize Android Intent.ACTION_SEND

I'm using Intent for sharing url and subject. In this intent filter showing all the sharing apps. i want only (facebook/gmail/message/skype/twitter) these option in popup. is this possible to customize sharing intent filter.
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
String shareBody = adapter.getDetails("url";
sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,"subject");
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareBody);
startActivity(Intent.createChooser(sharingIntent, "Share via"));
thanks
Yes, its possible Check out below which shows the filteration for Facebook,Gmail,Twitter.
Updated to Share Text + Image:
Select the image from the SDCard:
String fileName = "image-3116.jpg";
String externalStorageDirectory = Environment.getExternalStorageDirectory().toString();
String myDir = externalStorageDirectory + "/saved_images/"; // the
// file will be in saved_images
Uri uri = Uri.parse("file:///" + myDir + fileName);
Share via Twitter
Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, (String) v.getTag(R.string.app_name));
shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, (String) v.getTag(R.drawable.ic_launcher));
shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
PackageManager pm = v.getContext().getPackageManager();
List<ResolveInfo> activityList = pm.queryIntentActivities(shareIntent, 0);
for (final ResolveInfo app : activityList)
{
if ("com.twitter.android.PostActivity".equals(app.activityInfo.name))
{
final ActivityInfo activity = app.activityInfo;
final ComponentName name = new ComponentName(activity.applicationInfo.packageName, activity.name);
shareIntent.addCategory(Intent.CATEGORY_LAUNCHER);
shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
shareIntent.setComponent(name);
v.getContext().startActivity(shareIntent);
break;
}
}
Share via Facebook
Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, (String) v.getTag(R.string.app_name));
shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, (String) v.getTag(R.drawable.ic_launcher));
shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
PackageManager pm = v.getContext().getPackageManager();
List<ResolveInfo> activityList = pm.queryIntentActivities(shareIntent, 0);
for (final ResolveInfo app : activityList)
{
if ((app.activityInfo.name).startsWith("com.facebook.katana"))
{
final ActivityInfo activity = app.activityInfo;
final ComponentName name = new ComponentName(activity.applicationInfo.packageName, activity.name);
shareIntent.addCategory(Intent.CATEGORY_LAUNCHER);
shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
shareIntent.setComponent(name);
v.getContext().startActivity(shareIntent);
break;
}
}
Share via Gmail
Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, (String) v.getTag(R.string.app_name));
shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, (String) v.getTag(R.drawable.ic_launcher));
shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
PackageManager pm = v.getContext().getPackageManager();
List<ResolveInfo> activityList = pm.queryIntentActivities(shareIntent, 0);
for (final ResolveInfo app : activityList)
{
if ((app.activityInfo.name).contains("android.gm"))
{
final ActivityInfo activity = app.activityInfo;
final ComponentName name = new ComponentName(activity.applicationInfo.packageName, activity.name);
shareIntent.addCategory(Intent.CATEGORY_LAUNCHER);
shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
shareIntent.setComponent(name);
v.getContext().startActivity(shareIntent);
break;
}
}
Share via WhatsApp:
Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setType("text/html");
shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, (String) v.getTag(R.string.app_name));
shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, (String) v.getTag(R.drawable.ic_launcher));
shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
PackageManager pm = v.getContext().getPackageManager();
List<ResolveInfo> activityList = pm.queryIntentActivities(shareIntent, 0);
for (final ResolveInfo app : activityList) {
if ((app.activityInfo.name).contains("com.whatsapp")) {
final ActivityInfo activity = app.activityInfo;
final ComponentName name = new ComponentName(
activity.applicationInfo.packageName, activity.name);
shareIntent.addCategory(Intent.CATEGORY_LAUNCHER);
shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
shareIntent.setComponent(name);
v.getContext().startActivity(shareIntent);
break;
}
}
Single method for multiple functionalities
Code of share(String nameApp,String imagePath,String message) function:
public void share(String nameApp, String imagePath, String message) {
try {
List<Intent> targetedShareIntents = new ArrayList<Intent>();
Intent share = new Intent(android.content.Intent.ACTION_SEND);
share.setType("image/jpeg");
List<ResolveInfo> resInfo = getPackageManager()
.queryIntentActivities(share, 0);
if (!resInfo.isEmpty()) {
for (ResolveInfo info : resInfo) {
Intent targetedShare = new Intent(
android.content.Intent.ACTION_SEND);
targetedShare.setType("image/jpeg"); // put here your mime
// type
if (info.activityInfo.packageName.toLowerCase().contains(
nameApp)
|| info.activityInfo.name.toLowerCase().contains(
nameApp)) {
targetedShare.putExtra(Intent.EXTRA_SUBJECT,
"Sample Photo");
targetedShare.putExtra(Intent.EXTRA_TEXT, message);
targetedShare.putExtra(Intent.EXTRA_STREAM,
Uri.fromFile(new File(imagePath)));
targetedShare.setPackage(info.activityInfo.packageName);
targetedShareIntents.add(targetedShare);
}
}
Intent chooserIntent = Intent.createChooser(
targetedShareIntents.remove(0), "Select app to share");
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS,
targetedShareIntents.toArray(new Parcelable[] {}));
startActivity(chooserIntent);
}
} catch (Exception e) {
Log.v("VM",
"Exception while sending image on" + nameApp + " "
+ e.getMessage());
}
}
For attaching image on gmail, facebook, twitter with text use below code.
File filePath = new File("your image path");
share("gmail", filePath.toString(),"your comment");
share("facebook", filePath.toString(),"your comment");
share("twitter", filePath.toString(),"your comment");
Above given answer open facebook chat app on my phone. For the following worked !!
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
sharingIntent.putExtra(Intent.EXTRA_SUBJECT, "Subject");
sharingIntent.putExtra(Intent.EXTRA_TEXT, "Text...");
PackageManager packManager = getPackageManager();
List<ResolveInfo> resolvedInfoList = packManager.queryIntentActivities(sharingIntent, PackageManager.MATCH_DEFAULT_ONLY);
boolean resolved = false;
for(ResolveInfo resolveInfo: resolvedInfoList){
if(resolveInfo.activityInfo.packageName.startsWith("com.facebook.katana")){
sharingIntent.setClassName(
resolveInfo.activityInfo.packageName,
resolveInfo.activityInfo.name );
resolved = true;
break;
}
}
if(resolved){
startActivity(sharingIntent);
}else{
Builder alert = new AlertDialog.Builder(ActivityName.this);
alert.setTitle("Warning");
alert.setMessage("Facebook App not found");
alert.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int which)
{
dialog.dismiss();
}
});
alert.show();
}
You can't share Extras with image without using facebook sdk.
https://developers.facebook.com/x/bugs/332619626816423/

android sharing application

I have a few problems with my android app. I want to share some text and photo to fb and twitter. The first problem is that i can't copy the text from my textfield to the fb message ... i mean i have a text field with the text you want to share and 2 buttons ( fb, twitter) and the twitter side is working fine but i can't attach the text to the fb message ( the window appears on the push of the button but it's blank). Here is my code for sharing on facebbok:
Intent shareIntent = new Intent(
android.content.Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,
txt.getText());
shareIntent.putExtra(android.content.Intent.EXTRA_TEXT,
txt.getText());
PackageManager pm = v.getContext().getPackageManager();
List<ResolveInfo> activityList = pm.queryIntentActivities(
shareIntent, 0);
for (final ResolveInfo app : activityList) {
if ((app.activityInfo.name).contains("facebook")) {
final ActivityInfo activity = app.activityInfo;
final ComponentName name = new ComponentName(
activity.applicationInfo.packageName,
activity.name);
shareIntent.addCategory(Intent.CATEGORY_LAUNCHER);
shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
shareIntent.setComponent(name);
v.getContext().startActivity(shareIntent);
break;
}
}
My other problem is that my photo browser is giving me a path of the file like this: "external/images/media/photo" and i though that the problem is that i have to copy the extension too (.jpg etc.) but that's not it. If i use a direct path: "/mnt/sdcard/DCIM/01.jpg" it's working fine. Can someone help me how to find the direct path of the photo or how can i modify my code that it works with the first one:
private void share(String nameApp, String imagePath, String text) {
try {
List<Intent> targetedShareIntents = new ArrayList<Intent>();
Intent share = new Intent(android.content.Intent.ACTION_SEND);
share.setType("image/jpeg");
List<ResolveInfo> resInfo = getPackageManager()
.queryIntentActivities(share, 0);
if (!resInfo.isEmpty()) {
for (ResolveInfo info : resInfo) {
Intent targetedShare = new Intent(
android.content.Intent.ACTION_SEND);
targetedShare.setType("image/jpeg");
if (info.activityInfo.packageName.toLowerCase().contains(
nameApp)
|| info.activityInfo.name.toLowerCase().contains(
nameApp)) {
targetedShare.putExtra(Intent.EXTRA_SUBJECT, text);
targetedShare.putExtra(Intent.EXTRA_TEXT, text);
targetedShare.putExtra(Intent.EXTRA_STREAM,
Uri.fromFile(new File(imagePath)));
targetedShare.setPackage(info.activityInfo.packageName);
targetedShareIntents.add(targetedShare);
}
}
Intent chooserIntent = Intent.createChooser(
targetedShareIntents.remove(0), "Select app to share");
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS,
targetedShareIntents.toArray(new Parcelable[] {}));
startActivity(chooserIntent);
}
} catch (Exception e) {
}
}
Thx anticipated ...
You can get the exact path of your image as below, I have already shared the photo & text on FB & Twitter the way you have shared and its working fine for me also. Hope this will help you.
EDITED:
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
if (requestCode == SELECT_PICTURE) {
Uri selectedImageUri = data.getData();
selectedImagePath = getPath(selectedImageUri);
}
}
}
public String getPath(Uri uri) {
String[] projection = { MediaStore.Images.Media.DATA };
Cursor cursor = managedQuery(uri, projection, null, null, null);
int column_index = cursor
.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
}

Categories

Resources