【问题标题】:update contact picture on button from imageview android...?从imageview android更新按钮上的联系人图片...?
【发布时间】:2014-05-24 06:30:39
【问题描述】:

在我的应用程序中,我从相机或图库中获取图像并保存在 imageview 中。现在如何将这个 imageview 图像保存为我的联系人图片图像。

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");            
            }

    } 
}
}

【问题讨论】:

    标签: android performance android-layout android-intent android-listview


    【解决方案1】:
    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();
    
                }
            } 
        });
    

    添加:

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

    在您的清单中。

    【讨论】:

    • 在这个唯一打开的联系人中,当我选择联系人时,它不会在联系人图像上设置这个图像。
    • 你的图像设置在你的图像视图上正确吗??
    • 但对我来说是个好主意.. thnx
    猜你喜欢
    • 2013-01-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-20
    相关资源
    最近更新 更多