Football Fans: Download the 2012 Schedule App from Google Play!


Go Back   Android Forums > Android Development > Application Development

Application Development Dev Lounge for the Coder Folks



Reply
 
LinkBack Thread Tools
Old December 10th, 2009, 09:28 PM   #1 (permalink)
Junior Member
 
Join Date: Dec 2009
Location: Bath, OH, USA
Posts: 21
 
Device(s): Moto Droid
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to JoshKraker
Default Send an Image, ACTION_SEND

Code:
                MapImage Img = (MapImage) ((Button) v).getTag();
                ByteArrayOutputStream Os = new ByteArrayOutputStream();
                Img.Bm.compress(CompressFormat.JPEG, 100, Os);
                byte[] ImgBytes = null;
                try {
                    Os.flush();
                    ImgBytes = Os.toByteArray();
                    Os.close();
                } catch (IOException e) {}
                Intent i = new Intent(Intent.ACTION_SEND) ;
                i.setType("image/jpeg");
                i.putExtra(Intent.EXTRA_STREAM, ImgBytes);
                MyMv.getContext().startActivity(Intent.createChooser(i,"Send Image To:"));
The above code opens the Chooser dialog and shows all my option when when I click on any, they either throw an error (gmail), give a message saying "file not available" (picasa), or in SMS's case, opens a new message but no picture is shown.

Most of the examples I saw for sending an image using the chooser dialog are sending from a file or stored content somewhere (putExtra(EXTRA_STREAM, Uri)). Does anyone know the correct way to send when all we have is a Bitmap?

JoshKraker is offline  
Reply With Quote
Sponsors
Old December 11th, 2009, 11:55 PM   #2 (permalink)
Junior Member
 
Join Date: Dec 2009
Location: Bath, OH, USA
Posts: 21
 
Device(s): Moto Droid
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to JoshKraker
Default

Ok, so I gave in and tried saving the image to the sdcar first anf then creating a file URI using the following code

Code:
    // Omitted Class ...

    public Uri getThumbFileUri() {
        if (getThumbBm() == null) return null;
        File F = new File("file:///sdcard/MyProject/Images/Thumbs/" + PicId + ".jpg");
        Uri U = Uri.fromFile(F);
        return U;
    }
Code:
     // New Chooser Code ...

                MapImage Img = (MapImage) ((Button) v).getTag();
                Intent i = new Intent(Intent.ACTION_SEND);
                i.setType("image/jpeg");
                i.putExtra(Intent.EXTRA_STREAM, Img.getThumbFileUri());
                MyMv.getContext().startActivity(Intent.createChooser(i,"Send Image To:"));

I still get the Chooser dialog with all the same options of my previous post but when I select a send method I now get different errors

Gmail: Opens a new email showing an attachment of the file I am trying to attach with the same KB size, but when I check the email from them receiver, there is no attachment.

Messager: Shows an error "You cannot add this picture to your message"

Picasa: Shows an error "File not available"




Does that help any?
JoshKraker is offline  
Reply With Quote
Old December 13th, 2009, 01:12 PM   #3 (permalink)
New Member
 
Join Date: Dec 2009
Posts: 8
 
Device(s):
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Try inserting saving the image to the image gallery using the Media class and used the returned URL like this:

Code:
File imageFile = new File(Constants.SYSTEM_DYNOMASTER_DIR,filename);
FileOutputStream fout = new FileOutputStream(imageFile);
blankBitmap.compress(CompressFormat.JPEG, 100, fout);
fout.flush();
fout.close();
		
String url = Media.insertImage(context.getContentResolver(), imageFile.getAbsolutePath(), imageFile.getName(), imageFile.getName());

Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); 
shareIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
shareIntent.putExtra(Intent.EXTRA_TEXT, body);
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(url));
shareIntent.setType("image/jpeg");
context.startActivity(shareIntent);
Jeff
trackaroo is offline  
Reply With Quote
Old December 13th, 2009, 01:27 PM   #4 (permalink)
Junior Member
 
Join Date: Dec 2009
Location: Bath, OH, USA
Posts: 21
 
Device(s): Moto Droid
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to JoshKraker
Default

I tried it and it worked so I guess it gets me somewhere. However, I do not want to insert the image into the user's pictures, so is there a way to remove it once done?
JoshKraker is offline  
Reply With Quote
Old December 13th, 2009, 01:50 PM   #5 (permalink)
Junior Member
 
Join Date: Dec 2009
Location: Bath, OH, USA
Posts: 21
 
Device(s): Moto Droid
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to JoshKraker
Default

Ok, I figured it out. Your GRANT_READ.. permission got me thinking. I use the Java.Io to save my cached images to the SdCard and I'm passing the Uri to that file to the Intent. I guess it sandboxed my sdcard files so the intent was unable to read them, even if I gave it the GRANT_READ..

When I converted to using Context.openFileInput() to write the the file everything worked as expected.

Still, out of curiosity, it would be nice to know how to save files to the SdCard so that other Intents are able to read them.
JoshKraker is offline  
Reply With Quote
Old December 18th, 2009, 10:48 AM   #6 (permalink)
New Member
 
Join Date: Dec 2009
Posts: 8
 
Device(s):
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Can you post your code snippet? I'm curious as to what you did. Thanks.

Jeff
trackaroo is offline  
Reply With Quote
Old December 20th, 2009, 05:56 PM   #7 (permalink)
Junior Member
 
Join Date: Dec 2009
Location: Bath, OH, USA
Posts: 21
 
Device(s): Moto Droid
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to JoshKraker
Default

Sure,

I first save a Bitmap to the phone like so:

Code:
FileOutputStream Os = getAppContext().openFileOutput("Img" + _PicId + ".jpg", Context.MODE_WORLD_READABLE);
Bm.compress(Bitmap.CompressFormat.JPEG, 100, Os);
Os.close();
Then I get a Uri to send to the Chooser intent

Code:
                File F = getAppContext().getFileStreamPath("Img" + _PicId + ".jpg");
                Uri U = Uri.fromFile(F);

                Intent i = new Intent(Intent.ACTION_SEND);
                i.setType("image/jpg");
                i.putExtra(Intent.EXTRA_STREAM, U);
                getContext().startActivity(Intent.createChooser(i,"Send Image To:"));
JoshKraker is offline  
Reply With Quote
Old July 7th, 2010, 03:18 AM   #8 (permalink)
New Member
 
Join Date: Apr 2010
Posts: 1
 
Device(s):
Thanks: 0
Thanked 0 Times in 0 Posts
Default Want to send pictures one by one via mms to a fix no

package com.example.Mms;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
public class Mms extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Intent i = new Intent(Intent.ACTION_SEND) ;

String imageUri = null;
i.putExtra(Intent.EXTRA_STREAM,imageUri) ;
i.setType("image/jpeg") ;
startActivity(Intent.createChooser(i,"Send Image To:")) ;
}
}
I want to write a program which send pictures from one folder,one by one via mms to one fix no..

I have searched this program from Internet.When em running it through emulator it is opening a text box..I wrote text and added a no..and press the send button..but it is not showing a picture send via MMS
Please help me out..Thanks
tc_uzair@yahoo.com is offline  
Reply With Quote
Old July 30th, 2010, 04:04 AM   #9 (permalink)
New Member
 
Join Date: Oct 2009
Posts: 4
 
Device(s):
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Have you found anyway to do this without saving the picture into the phone ? I'd like to send an image file that my app gets from my server and then be able to send it.
pedroteixeira07 is offline  
Reply With Quote
Old February 3rd, 2011, 07:17 AM   #10 (permalink)
New Member
 
Join Date: Dec 2010
Posts: 7
 
Device(s):
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hello Experts,

now i am working on one android application which needs
1) to play an audio song to callee when call is lifted.
2) call has to be disconnected after audio playing completed.

please help me Experts if you have any suggestions for me ...

Thank you in advance..please do reply
golemnagesh is offline  
Reply With Quote
Sponsors
Reply

Bookmarks


Go Back   Android Forums > Android Development > Application Development User CP
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
"Sorry, you can't send this image" MIIISTER NEUGIT Developer 101 0 November 19th, 2010 07:03 PM
How do you send a text message using the keyboard instead of tapping send on-screen? tx_brandon Epic 4G - Support and Troubleshooting 2 September 13th, 2010 04:08 AM
Can't send gmails. Recieve yes, send no Joe Eris Eris - All Things Root 3 September 5th, 2010 12:53 PM
How to revert from custom recovery image to stock recovery image? Deusdies Nexus - All Things Root 2 July 2nd, 2010 05:32 AM
Image Transfer - Wirelessly send photos to your computer joet3ch Application Announcements 1 May 1st, 2010 07:53 AM



All times are GMT -5. The time now is 11:38 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
Custom vBulletin Skins by: Relivo