I am working on one of the android app where i am getting lat long and want to send it to email and facebook
one way is to share google static image url
but can we attach image from this static url and send it via email or facebook...
I am working on one of the android app where i am getting lat long and want to send it to email and facebook
one way is to share google static image url
but can we attach image from this static url and send it via email or facebook...
Here is the code which you can use, basically use a WebView to take a snapshot and save it somewhere.
private static Bitmap pictureDrawable2Bitmap(PictureDrawable pictureDrawable){
Bitmap bitmap = Bitmap.createBitmap(pictureDrawable.getIntrinsicWidth(),pictureDrawable.getIntrinsicHeight(), Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
canvas.drawPicture(pictureDrawable.getPicture());
return bitmap;
}
public void getImage()
{
WebView web=(WebView)findViewById(R.id.your_webviews_id);
Picture p=web.capturePicture();
SharedPreferences prefs=con.getSharedPreferences("File_COUNT", con.MODE_PRIVATE);
//int count=prefs.getInt(//"COUNT", 0);
long rand= System.currentTimeMillis();
File root=new File(Environment.getExternalStorageDirectory()+"/Maps");
root.mkdirs();
File save_img=new File(root.getAbsolutePath()+"/"+rand+".png");
//OutputStream os;
try {
Bitmap bmp = pictureDrawable2Bitmap(new PictureDrawable(p));
FileOutputStream out = new FileOutputStream(save_img.getAbsolutePath());
bmp.compress(Bitmap.CompressFormat.PNG, 90, out);
out.close();
Toast.makeText(con, "Save successful", Toast.LENGTH_SHORT).show();
Intent shareIntent = new Intent(Intent.ACTION_SEND);
MimeTypeMap mime = MimeTypeMap.getSingleton();
String type = mime.getMimeTypeFromExtension("png");
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(save_img));
shareIntent.setType(type);
startActivity(Intent.createChooser(shareIntent, "Share Using"));
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
Toast.makeText(con, "File not able to be saved. Please restart app", Toast.LENGTH_SHORT).show();
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Toast.makeText(con, "I/O error", Toast.LENGTH_SHORT).show();
}
}
Hence ,to send an email, just attach this image to the email and call the email Intent.