Skip to main content

Save Bitmap and sent it with Email attachment ANDROID

It is very simple to save BITMAP into image


 if (BITMAP != null) {  
                               try {  
                                    ByteArrayOutputStream bytes = new ByteArrayOutputStream();  
                                    BITMAP.compress(Bitmap.CompressFormat.PNG, 40,  
                                              bytes);  
                                    // you can create a new file name ".jpg" in  
                                    // sdcard folder.  
                                    String pngUri = Environment  
                                              .getExternalStorageDirectory()  
                                              + File.separator  
                                              + _KNAME  
                                              + "_"  
                                              + General_Class.selectitem_  
                                              + "_"  
                                              + _BVALUE  
                                              + "_View.jpg";  
                                    newFile = new File(pngUri);  
                                    newFile.createNewFile();  
                                    // write the bytes in file  
                                    FileOutputStream fo = new FileOutputStream(newFile);  
                                    fo.write(bytes.toByteArray());  
                                    // remember close de FileOutput  
                                    fo.close();  
                               } catch (Exception e) {  
                                    Log.d("error in save image", "-->"  
                                              + e.getMessage().toString());  
                               }  
                          }  

Use that image path in share intent.

 Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);  
                // set the type  
                shareIntent.setType("text/plain");  
                // add a subject  
                shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,  
                          "Email with attachmetn");  
                // build the body of the message to be shared  
                String shareMessage = "\n";  
                // add the message  
                shareIntent.putExtra(android.content.Intent.EXTRA_TEXT,  
                          shareMessage);  
                shareIntent.putExtra(android.content.Intent.EXTRA_STREAM,  
                          Uri.fromFile(newFile));  
                // start the chooser for sharing  
                startActivity(Intent.createChooser(shareIntent,  
                          "Please select sharing medium"));  

enjoy coding...

Comments

Popular posts from this blog

Multi-Selection ListView ANDROID with CheckBox PART-2

Check Below Code : mainActivity.java package com.example.listviewcheckbox; import java.util.ArrayList; import android.app.Activity; import android.content.Context; import android.graphics.Bitmap; import android.os.Bundle; import android.util.Log; import android.view.LayoutInflater; import android.view.Menu; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.CheckBox; import android.widget.ImageView; import android.widget.ListView; import android.widget.TextView; import android.widget.Toast; public class MainActivity extends Activity { private ListView listview; ArrayList<String> items = new ArrayList<String>(); private int count; private boolean[] thumbnailsselection; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(...

Multi-Selection ListView ANDROID with CheckBox

Shaadi.com Indian Matrimonials Download code Create New Android Project: in res/layout/main.xml create new layout for list row : in res/layout/list_row.xml in your Main Activity Class: Create Class name mItems: Create New Class name SelectViewHolder: Create New Class name SelectArrayAdapter: Download Source Code Click Here : Check PART2 for more detail. Shaadi.com Matrimonials

Android - Notifications - 3 (Applying a big view style to a notification)

Big picture style Bitmap icon1 = BitmapFactory.decodeResource(getResources(), R.drawable.dhaval1); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder( this).setAutoCancel(true) .setContentTitle("DJ-Android notification") .setSmallIcon(R.drawable.ic_launcher).setLargeIcon(icon1) .setContentText("Hello World!"); NotificationCompat.BigPictureStyle bigPicStyle = new NotificationCompat.BigPictureStyle(); bigPicStyle.bigPicture(icon1); bigPicStyle.setBigContentTitle("Dhaval Sodha Parmar"); mBuilder.setStyle(bigPicStyle); // Creates an explicit intent for an Activity in your app Intent resultIntent = new Intent(this, testActivity.class); // The stack builder object will contain an artificial ba...