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

Android - Google MAP V2 PART 1

Download Full Code  of PART-1 , 2 , 3 , 4 Download and configure Google Play Services Library in Eclipse Google Map for Android is now integrated with Google Play Services. So we need to set up Google Play Service Library for developing Google Map application in Android. Get the API key for Google Maps v2: Linux  :  For any other OS use this :  keytool -list -v -alias androiddebugkey \ -keystore <path_to_debug_keystore>debug.keystore \ -storepass android -keypass android Register with the Google APIs Console :    Google APIs Console  Select here the  Services  entry: Activate the  Google Maps Android API v2 . Register your application via its package in this console together with the SHA-1 fingerprint of your signature key. Click on Create new Android Key.. Add you SHA-1 and your package name in to box like example given in alert box. Support library...

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 - update status Linked-IN

jars: 1. linkedin-j-android.jar 2. scribe-1.3.1.jar MainActivity: package com.testshare; import java.util.EnumSet; import org.scribe.oauth.OAuthService; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.util.Log; import com.google.code.linkedinapi.client.LinkedInApiClient; import com.google.code.linkedinapi.client.LinkedInApiClientFactory; import com.google.code.linkedinapi.client.enumeration.NetworkUpdateType; import com.google.code.linkedinapi.schema.Network; public class TestshareActivity extends Activity { private int LINKEDIN_OAUTH_RESULT_CODE = 4000; private OAuthService service; private static final String PROTECTED_RESOURCE_URL = "http://api.linkedin.com/v1/people/~"; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(...