0

in my application i fetch image from camera or gallery and save in imageview. now how can i save this imageview image as my contact picture image.

detail.java

camera.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); 
                startActivityForResult(cameraIntent, CAMERA_REQUEST); 
            }
        });

        //gallery picture
        galary.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                Intent photoPickerIntent = new Intent(Intent.ACTION_GET_CONTENT);
                photoPickerIntent.setType("image/*");
                startActivityForResult(photoPickerIntent, 1);
            }
        });

        save.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub
                Intent image= new Intent(Intent.)

            }
        });



    }



    protected void onActivityResult(int requestCode, int resultCode, Intent data) {  

        if (requestCode == CAMERA_REQUEST && resultCode == RESULT_OK) {  

            Bitmap photo = (Bitmap) data.getExtras().get("data"); 
            photo1.setImageBitmap(photo);
        }
        else 
        {
            if (data != null && resultCode == RESULT_OK) 
            {              

                  Uri selectedImage = data.getData();

                  String[] filePathColumn = {MediaStore.Images.Media.DATA};
                  Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null);
                  cursor.moveToFirst();
                  int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
                  String filePath = cursor.getString(columnIndex);
                  cursor.close();

                  if(photo != null && !photo.isRecycled())
                  {
                      photo = null;                
                  }

                  photo = BitmapFactory.decodeFile(filePath);
                  photo1.setBackgroundResource(0);
                  photo1.setImageBitmap(photo);              
            }
            else 
            {
                Log.d("Status:", "Photopicker canceled");            
            }

    } 
}
}
Hariharan
  • 24,741
  • 6
  • 50
  • 54

1 Answers1

0
setimage.setOnClickListener(new View.OnClickListener() {

         public void onClick(View v){
            Context context= getApplicationContext();
                            Bitmap icon= BitmapFactory.decodeResource(context.getResources(),
                    R.id.your_img_view);
            try {  
                 Intent myIntent = new Intent();        myIntent.setAction(Intent.ACTION_ATTACH_DATA); 
myIntent.setType("image/jpeg"); 
myIntent.putExtra(Intent.EXTRA_STREAM, icon);
 startActivity(myIntent); 

            } catch (ActivityNotFoundException e) {  
              e.printStackTrace();

            }
        } 
    });

add:

    <uses-permission android:name="android.permission.WRITE_CONTACTS" />
 <uses-permission android:name="android.permission.READ_CONTACTS" />

in your manifest.

kgandroid
  • 5,507
  • 5
  • 39
  • 69