android sharing application - android

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);
}

Related

show JUST ONCE and ALWAYS option using Intent.createChooser

I open chooser dialog using Intent.createChooser() method. But in that dialog I can't see "JUST ONCE" and "ALWAYS" options.
I want this type of chooser dialog with Intent.createChooser() method
here is my code.
File mFile = new File("give your file path here");
String type = "video/mp4";
Intent viewDoc = new Intent(Intent.ACTION_VIEW);
viewDoc.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
viewDoc.setFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
Uri contentUri = FileProvider.getUriForFile(this, "com.xyz.fileprovider", mFile);
viewDoc.setDataAndType(contentUri, type);
PackageManager pm = getPackageManager();
apps = pm.queryIntentActivities(viewDoc, PackageManager.MATCH_DEFAULT_ONLY);
ArrayList<Intent> targetIntents = new ArrayList<Intent>();
for (ResolveInfo resolveInfo : apps) {
String packageName = resolveInfo.activityInfo.packageName;
grantUriPermission(packageName, contentUri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
if (!BuildConfig.APPLICATION_ID.equals(packageName)) {
Intent targetIntent = new Intent(Intent.ACTION_VIEW); // targetIntent.setDataAndType(contentUri, type);
targetIntent.setPackage(packageName);
targetIntent.setDataAndType(contentUri, type);
targetIntents.add(targetIntent);
}
}
if (type == null || type.equals("") || targetIntents.size() <= 0) { //application/octet-stream
android.app.AlertDialog alertDialog = new android.app.AlertDialog.Builder(this).create();
alertDialog.setTitle(getResources().getString(R.string.app_name));
alertDialog.setMessage(getResources().getString(R.string.offline_file_not_supported_error));
alertDialog.setButton(DialogInterface.BUTTON_NEUTRAL, "OK", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
alertDialog.show();
} else {
Intent chooserIntent = Intent.createChooser(targetIntents.remove(0), "Open file with");
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, targetIntents.toArray(new Parcelable[]{}));
startActivity(chooserIntent);
//startActivity(viewDoc);
}
But after this code I get chooser dialog like below
But i need JUST ONCE and ALWAYS option in this dialog.
I used below mentioned code because I want to remove my own app from chooser.
for (ResolveInfo resolveInfo : apps) {
String packageName = resolveInfo.activityInfo.packageName;
grantUriPermission(packageName, contentUri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
if (!BuildConfig.APPLICATION_ID.equals(packageName)) {
Intent targetIntent = new Intent(Intent.ACTION_VIEW); // targetIntent.setDataAndType(contentUri, type);
targetIntent.setPackage(packageName);
targetIntent.setDataAndType(contentUri, type);
targetIntents.add(targetIntent);
}
}

an android file picker or camera for taking pictures or videos not working on nexus 4

I am trying to open an android file picker or camera for taking pictures or videos using the following code:
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == PICKFILE_RESULT_CODE && Activity.RESULT_OK == resultCode) {
try {
// Get the Uri of the selected file
Uri uri = data.getData();
LogS.d("File Uri: " + uri.toString());
// Get the path
String path = BeanUtils.getPath(getActivity().getApplicationContext(), uri);
AnnexFile f = new AnnexFile(path);
if (!addedFiles.contains(f)) {
addFileToLayout(f);
addedFiles.add(f);
} else {
Toast.makeText(getActivity(), R.string.you_allready_added_this_file_, Toast.LENGTH_SHORT).show();;
}
} catch (Exception e) {
LogS.e(e);
Toast.makeText(getActivity(), getString(R.string.file_manager_invalid), Toast.LENGTH_LONG).show();
}
} else if (requestCode == CAMERA_CAPTURE_IMAGE_REQUEST_CODE && Activity.RESULT_OK == resultCode) {
try {
Uri uri = data.getData();
LogS.d("File Uri: " + uri.toString());
// Get the path
String path = BeanUtils.getPath(getActivity().getApplicationContext(), uri);
AnnexFile f = new AnnexFile(path);
if (!addedFiles.contains(f)) {
addFileToLayout(f);
addedFiles.add(f);
} else {
Toast.makeText(getActivity(), R.string.you_allready_added_this_file_, Toast.LENGTH_SHORT).show();;
}
} catch (Exception e) {
LogS.e(e);
Toast.makeText(getActivity(), getString(R.string.file_manager_invalid), Toast.LENGTH_LONG).show();
}
}
super.onActivityResult(requestCode, resultCode, data);
}
private void openImageIntent() {
// Camera.
final List<Intent> cameraIntents = new ArrayList<Intent>();
final Intent captureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
final PackageManager packageManager = getActivity().getPackageManager();
final List<ResolveInfo> listCam = packageManager.queryIntentActivities(captureIntent, 0);
for (ResolveInfo res : listCam){
final String packageName = res.activityInfo.packageName;
final Intent intent = new Intent(captureIntent);
intent.setComponent(new ComponentName(res.activityInfo.packageName, res.activityInfo.name));
intent.setPackage(packageName);
cameraIntents.add(intent);
}
final Intent videoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
final List<ResolveInfo> listVideoCam = packageManager.queryIntentActivities(videoIntent, 0);
for (ResolveInfo res : listVideoCam){
final String packageName = res.activityInfo.packageName;
final Intent intent = new Intent(videoIntent);
intent.setComponent(new ComponentName(res.activityInfo.packageName, res.activityInfo.name));
intent.setPackage(packageName);
cameraIntents.add(intent);
}
//FileSystem
final Intent galleryIntent = new Intent();
galleryIntent.setType("image/*;video/*");
galleryIntent.setAction(Intent.ACTION_GET_CONTENT);
// Chooser of filesystem options.
final Intent chooserIntent = Intent.createChooser(galleryIntent, "Select Source");
// Add the camera options.
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, cameraIntents.toArray(new Parcelable[]{}));
startActivityForResult(chooserIntent, CAMERA_CAPTURE_IMAGE_REQUEST_CODE);
}
The code works perfect on Samsung S4 and Sony Experia J but fails on Nexus 4 (android 5.1.1). When I debugged the application on nexus 4 I found that the following Uri uri = data.getData(); is null if the end user tries to make a picture. The application works on all devices if the user tries to make a video or to open an existing media file.
When I debugged the application on nexus 4 I found that the following Uri uri = data.getData(); is null if the end user tries to make a picture
You are assuming that ACTION_IMAGE_CAPTURE returns a result in the form of a Uri. It is not documented to do so. There are thousands of camera apps, pre-installed and user-installed. Many of them will advertise support for ACTION_IMAGE_CAPTURE. None have to return a Uri result.

android filter app returns two twitter

I am trying to filter the app i have in the phone, facebook and twitter are what I want to find. Below is the code i use, and it works fine before, it filter twitter and facebook for me to post something. Then later it become i filter two twitter apps. Anyone know why?
I use debug more and found these, how come i get two twitter package. I have tried delete and reinstall my twitter app, it won't work.
ResolveInfo{445f8600 com.twitter.android/.composer.ComposerActivity m=0x608000}
ResolveInfo{445f14d0 com.twitter.android/.DMActivity m=0x608000}
private void shareContent() {
UtuBaseActivity activity = (UtuBaseActivity) getActivity();
if (activity == null || activity.isFinishing())
return;
if (promotionDetail == null)
return;
String title = getResources().getString(R.string.share_chooser_title);
String app_name = getResources().getString(R.string.app_name);
List<Intent> targetShareIntents = new ArrayList<>();
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.setType("text/plain");
List<ResolveInfo> resInfos = activity.getPackageManager().queryIntentActivities(shareIntent, 0);
if (!resInfos.isEmpty()) {
for (ResolveInfo resInfo : resInfos) {
String packageName = resInfo.activityInfo.packageName;
if (packageName.contains("com.twitter.android") || packageName.contains("com.facebook.katana")) {
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_SUBJECT, app_name);
intent.putExtra(Intent.EXTRA_TEXT, promotionDetail.getCoverpicture());
intent.setPackage(packageName);
targetShareIntents.add(intent);
}
}
if (!targetShareIntents.isEmpty()) {
Intent chooserIntent = Intent.createChooser(targetShareIntents.remove(0), title);
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, targetShareIntents.toArray(new Parcelable[]{}));
startActivity(chooserIntent);
} else {
// As fallback, launch sharer.php in a browser
String sharerUrl = "https://www.facebook.com/sharer/sharer.php?u=" + promotionDetail.getCoverpicture();
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(sharerUrl));
startActivity(i);
}
}
}
add this, it works tested.
check parent name equals to com.twitter.android.MainActivity
private void shareContent() {
UtuBaseActivity activity = (UtuBaseActivity) getActivity();
if (activity == null || activity.isFinishing())
return;
if (promotionDetail == null)
return;
String title = getResources().getString(R.string.share_chooser_title);
String app_name = getResources().getString(R.string.app_name);
List<Intent> targetShareIntents = new ArrayList<>();
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.setType("text/plain");
List<ResolveInfo> resInfos = activity.getPackageManager().queryIntentActivities(shareIntent, 0);
if (!resInfos.isEmpty()) {
for (ResolveInfo resInfo : resInfos) {
String packageName = resInfo.activityInfo.packageName;
String parentName = resInfo.activityInfo.parentActivityName;
if (packageName.contains("com.twitter.android") || packageName.contains("com.facebook.katana")) {
if (packageName.contains("com.twitter.android"))
if (!parentName.equals("com.twitter.android.MainActivity"))
continue;
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_SUBJECT, app_name);
intent.putExtra(Intent.EXTRA_TEXT, promotionDetail.getCoverpicture());
intent.setPackage(packageName);
targetShareIntents.add(intent);
}
}
if (!targetShareIntents.isEmpty()) {
Intent chooserIntent = Intent.createChooser(targetShareIntents.remove(0), title);
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, targetShareIntents.toArray(new Parcelable[]{}));
startActivity(chooserIntent);
} else {
// As fallback, launch sharer.php in a browser
String sharerUrl = "https://www.facebook.com/sharer/sharer.php?u=" + promotionDetail.getCoverpicture();
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(sharerUrl));
startActivity(i);
}
}
}

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/

Image could not be loaded on twitter

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;
}
}
}

Categories

Resources