Sharing an Image from Bitmap in Android

I had a project that required downloading an image from the internet then calling the sharing intent to share that bitmap, I went through countless entries until I reached the conclusion that it is impossible to share an image directly from a bitmap object, the bitmap must be saved first and then you can share it and if you dont want to keep a copy on disk you have to explicitly delete it.

Here are how I ended up doing it.

1. Save BitMap

String file_path = Environment.getExternalStorageDirectory().getAbsolutePath() +
File dir = new File(file_path);
File file = new File(dir, name);
FileOutputStream fOut;
try {
fOut = new FileOutputStream(file);
abmp.compress(Bitmap.CompressFormat.PNG, 85, fOut);
} catch (Exception e) {

2. Share URI from file

Uri uri = Uri.fromFile(file);
Intent intent = new Intent();

intent.putExtra(android.content.Intent.EXTRA_SUBJECT, "");
intent.putExtra(android.content.Intent.EXTRA_TEXT, "");

intent.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(Intent.createChooser(intent, "Share Cover Image"));


If you can come up with a hack to share directly from BitMap please do share, but I dont believe it is possible.



Temboo the on stop shop API

There is no way to capture the value of online APIs, basically they save you from the tedious effort of reinventing the wheel or maintaining a costly back end. Shifting your focus from algorithm to customer experience, the only expense here is integrating the API with your product. While most APIs rely on JSON calls of one kind or another integrating them into your code can be costly and time consuming, especially if you use multiple APIs, also it is quite time consuming to keep track of APIs as they get updated. also there is a certain degree of effort required to learn how to efficiently use each API. (API calls economics)

Temboo is a one stop SDK, providing a single interface for an ever expanding list of APIs and available in 7 languages!

Temboo standardizes the way you interact with an ever expanding list of APIs, updating frequently to match any changes in these APIs keeping your products in sync with them transparently. Basically Temboo is a wrapper that provides a standard API to a bunch of APIs and its available in a bunch of languages. With the end result being the ability to integrate any API you want into your code without spending tedious hours reading their documentation and testing various messages and their responses.

It gets even better, through the website you can test various APIs through a simple web interface, testing various test cases, by filling the variables in text boxes. It even provides you with a code snippet suitable to be plugged directly into your code. Basically saving you hours of testing and integration.

When I mentioned that their APIs list is ever expanding I really meant it, every time I visit the site I can see few more APIs added to the list, they just added twitter, and now I’m considering unifying all my products API usage and piping it through Temboos. I’m rarely that excited about a new product, but this one seriously blew me away.


Using Java With Exchange Server to send emails

In this post I’m going to explain how to send mails through Exchange server using the javax.mail package library , which is a bit more tricky than using other mails servers such as gmail.

The authentication part is the most complicated part of all of this, and here is a really interesting tip, if you try it too many times, your account gets locked and you’d not even know till much later, this actually happened with me and I think i wasted about 2 hours going in circles till i figured out that my account was actually locked, i phoned the helpdesk, 10 minutes later my app was sending mails.

and here is the code:

package sendmail;

package sendmail;

* To change this template, choose Tools | Templates
* and open the template in the editor.
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMessage.RecipientType;
import java.util.*;

* @author user
public class Mailmanx {

// new MailWithPasswordAuthentication().run();

String body,subject;
public void mail_alist(ArrayList lines,String asubject)
//String user, pass, subject, body;

subject=”Alert :\t”+asubject;
body=”START of message\n”;

for(int i=0; i<lines.size(); i++) {
try {
Sendmail(body, subject);
} catch (MessagingException ex) {
Logger.getLogger(Mailmanx.class.getName()).log(Level.SEVERE, null, ex);

public void Sendmail(String body, String subject) throws MessagingException ////this is used to send the emails

Message message = new MimeMessage(getSession());

////test bit
// message.addRecipient(RecipientType.TO, new InternetAddress(""));///change to dist list
// message.addFrom(new InternetAddress[] { new InternetAddress("") });
///end test bit

message.addRecipient(RecipientType.TO, new InternetAddress(""));///change to dist list
message.addFrom(new InternetAddress[] { new InternetAddress("") });

message.setContent(body, "text/plain");


private Session getSession() {
Authenticator authenticator = new Authenticator();

Properties properties = new Properties();
properties.setProperty("mail.smtp.submitter", authenticator.getPasswordAuthentication().getUserName());
properties.setProperty("mail.smtp.auth", "true");

properties.setProperty("", "Mail.server.url");
properties.setProperty("mail.smtp.port", "25");

return Session.getInstance(properties, authenticator);

private class Authenticator extends javax.mail.Authenticator {
private PasswordAuthentication authentication;

public Authenticator() {
String username = "corp-domain\\user";
String password = "pass";
authentication = new PasswordAuthentication(username, password);

protected PasswordAuthentication getPasswordAuthentication() {
return authentication;