我想打一个对话屏幕像WhatsApp的头像对话框屏幕屏幕、我想、对话框、头像

2023-09-09 21:05:13 作者:命中不缺狗

朋友你好......

我目前正在做一个对话使用隐式意图在这里我想告诉我的对话像WhatsApp的(个人资料照片屏幕),并在此屏幕的WhatsApp使用命名为删除照片额外字段。当我尽量让同类型的屏幕对话的话,我无法添加这些额外的字段(删除照片)。我已经做了所有code。其做工精细三个选项对话框一样(图库,照片,摄像头),我无法处理所有这些在onActivityResult()。我送我的所有的源$ C ​​$词都试过很多努力,但我不能够找到解决办法这样做。 PLZ .....朋友帮我从这个。

在此$ C $词时只需创建一个命名为openFileChooser(),其中我有写所有的$ C $下创建对话框屏幕的方法和处理这一成果onActivityResult()

下面是我的code

ProfilePhotoActivity.java

 公共类ProfilePhotoActivity扩展活动实现OnClickListener {
    的ImageButton回,editPhoto,selectAction;
    ImageView的imgCamera;
    私有静态最终诠释FILECHOOSER_RESULT code = 2888;
    受保护的静态最终诠释CAMERA_REQUEST = 0;
    受保护的静态最终诠释GALLERY_PICTURE = 1;
    私人乌里mCapturedImageURI = NULL;
    意向意图;

    @覆盖
    保护无效的onCreate(包savedInstanceState){
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow()。setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        的setContentView(R.layout.activity_profilephoto);

        回到=(的ImageButton)findViewById(R.id.btn_back);
        editPhoto =(的ImageButton)findViewById(R.id.ibEditPhoto);
        selectAction =(的ImageButton)findViewById(R.id.ibSelectAction);

        imgCamera =(ImageView的)findViewById(R.id.imvProfilePhoto);

        editPhoto.setOnClickListener(本);
        selectAction.setOnClickListener(本);
        back.setOnClickListener(本);
    }

    @覆盖
    公共无效的onClick(视图v){

        开关(v.getId()){
        案例R.id.btn_back:
            ProfilePhotoActivity.this.finish();
            打破;

        案例R.id.ibEditPhoto:
            openFileChooser(NULL,NULL);
        // startDialog();


            打破;
        案例R.id.ibSelectAction:
            打破;
        }
    }

     公共无效openFileChooser(ValueCallback<乌里> uploadMsg,串acceptType){

            尝试{

             //在SD卡创建AndroidExampleFolder

             文件imageStorageDir =新的文件(
               Environment.getExternalStoragePublicDirectory(
                 Environment.DIRECTORY_PICTURES)
                 AndroidExampleFolder);

             如果(!imageStorageDir.exists()){
              //在SD卡创建AndroidExampleFolder
              imageStorageDir.mkdirs();
             }

             //创建相机拍摄的图像文件路径和名称
             档案文件=新的文件(
               imageStorageDir +文件分割符+IMG_
                 +将String.valueOf(System.currentTimeMillis的())
                 +.JPG);

             mCapturedImageURI = Uri.fromFile(文件);

             //摄像机捕捉图像的意图
             最终意图captureIntent =新的意图(
               android.provider.MediaStore.ACTION_IM​​AGE_CAPTURE);

             captureIntent.putExtra(MediaStore.EXTRA_OUTPUT,mCapturedImageURI);

             意图I =新的意图(Intent.ACTION_PICK);
            // i.addCategory(Intent.CATEGORY_OPENABLE);
             i.setType(图像/ *);

             //创建文件选择意向
             意图chooserIntent = Intent.createChooser(我,图像选择器);

             //设置相机的意向文件选择
             chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS
               新Parcelable [] {captureIntent});

             //在选择图像调用onActivityResult活动的方法
             startActivityForResult(chooserIntent,FILECHOOSER_RESULT code);

            }
            赶上(例外五){
             Toast.makeText(getBaseContext(),异常:+ E,
               Toast.LENGTH_LONG).show();
            }

           }
     保护无效onActivityResult(INT申请code,INT结果code,意图意图){

          如果(要求code == FILECHOOSER_RESULT code)
          {
              如果(要求code == GALLERY_PICTURE)
                    {
                        如果(结果code == RESULT_OK)
                        {
                            如果(意向!= NULL)
                            {
                                //我们BitmapDrawable的缩略图
                                BitmapDrawable bmpDrawable = NULL;

                                //尝试从意图使用数据来检索图像
                                光标光标= getContentResolver()查询(intent.getData(),NULL,NULL,NULL,NULL);

                                如果(光标!= NULL)
                                {
                                    cursor.moveToFirst();

                                    INT IDX = cursor.getColumnIndex(ImageColumns.DATA);
                                    串fileSrc = cursor.getString(IDX);
                                    位图galleryBitmap = BitmapFactory.de codeFILE(fileSrc); //负荷preVIEW图像
                                    galleryBitmap = Bitmap.createScaledBitmap(galleryBitmap,200,200,真);


                                    字符串文件路径= Environment.getExternalStorageDirectory()
                                    .getAbsolutePath()+/ TimeChat /图片/+ System.currentTimeMillis的()+JPG;

                                    //imgCamera.setRotation(0);
                                    imgCamera.setImageBitmap(galleryBitmap);
//将writeToFile(文件路径,galleryBitmap);
                                }
                                其他
                                {
                                    bmpDrawable =新BitmapDrawable(getResources(),intent.getData()getPath());
                                    imgCamera.setImageDrawable(bmpDrawable);
                                }
                            }
                            其他
                            {
                                Toast.makeText(getApplicationContext(),取消,Toast.LENGTH_SHORT).show();
                            }
                        }
                        否则,如果(结果code == RESULT_CANCELED)
                        {
                            Toast.makeText(getApplicationContext(),取消,Toast.LENGTH_SHORT).show();
                        }
                    }
                    否则,如果(要求code == CAMERA_REQUEST)
                    {
                        如果(结果code == RESULT_OK)
                        {
                            如果(intent.hasExtra(数据))
                            {
                                //从意图位图
                                。位图cameraBitmap =(位图)intent.getExtras()获得(数据);

                                    字符串文件路径= Environment.getExternalStorageDirectory()
                                .getAbsolutePath()+/ TimeChat /图片/+ System.currentTimeMillis的()+JPG;

                                //更新与位图图像视图
                                imgCamera.setImageBitmap(cameraBitmap);
                            //将writeToFile(文件路径,circleBitmap);

                            }
                            否则,如果(intent.getExtras()== NULL){

                                Toast.makeText(getApplicationContext(),没有额外取回!,Toast.LENGTH_SHORT).show();

                                BitmapDrawable缩略图=新BitmapDrawable(getResources(),intent.getData()getPath());

                                //更新与新创建绘制图像视图
                                imgCamera.setImageDrawable(缩略图);

                            }

                        }
                        否则,如果(结果code == RESULT_CANCELED){
                            Toast.makeText(getApplicationContext(),取消,Toast.LENGTH_SHORT).show();
                        }
                    }
          }
         }


    @覆盖
    公共无效onBack pressed(){
        // TODO自动生成方法存根
        super.onBack pressed();
        ProfilePhotoActivity.this.finish();
    }

}
 
iOS微信终于更新 朋友圈可以发长视频了

解决方案

这看起来将是一个问题:

 如果(要求code == FILECHOOSER_RESULT code)
          {
              如果(要求code == GALLERY_PICTURE)
 

除非FILECHOOSER_RESULT code和GALLERY_PICTURE是相同的整数,然后语句将永远不会过去。

hello Friends....

I am currently trying to make a Dialog using Implicit Intent where i want to show my Dialog like whatsApp(Profile Photo Screen) and in this screen whatsApp are using extra field named as "Remove Photo". When i try to make same type of screen Dialog then i am unable to add this extra field("Remove Photo"). i have done all code. its working fine for three option in Dialog like(Gallery,Photo,Camera) and i am unable to handle these all in onActivityResult() . I am sending my all source code i have tried much hard , but i am not able to find the solution to do so. plz..... friends help me out from this.

In this code i am simply create a method named as openFileChooser() in which i have write all the code for creating Dialog Screen and handle this outcomes in onActivityResult()

Here Is my code

ProfilePhotoActivity.java

public class ProfilePhotoActivity extends Activity implements OnClickListener{
    ImageButton back, editPhoto, selectAction;
    ImageView imgCamera;
    private static final int FILECHOOSER_RESULTCODE   = 2888;
    protected static final int CAMERA_REQUEST = 0;
    protected static final int GALLERY_PICTURE = 1;
    private Uri mCapturedImageURI = null;
    Intent intent;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_profilephoto);

        back=(ImageButton)findViewById(R.id.btn_back);
        editPhoto=(ImageButton)findViewById(R.id.ibEditPhoto);
        selectAction=(ImageButton)findViewById(R.id.ibSelectAction);

        imgCamera=(ImageView)findViewById(R.id.imvProfilePhoto);

        editPhoto.setOnClickListener(this);
        selectAction.setOnClickListener(this);
        back.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {

        switch (v.getId()) {
        case R.id.btn_back:
            ProfilePhotoActivity.this.finish();
            break;

        case R.id.ibEditPhoto:
            openFileChooser(null, null);
        //  startDialog();


            break;
        case R.id.ibSelectAction:
            break;
        }
    }

     public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType){  

            try{    

             // Create AndroidExampleFolder at sdcard

             File imageStorageDir = new File(
               Environment.getExternalStoragePublicDirectory(
                 Environment.DIRECTORY_PICTURES)
                 , "AndroidExampleFolder");

             if (!imageStorageDir.exists()) {
              // Create AndroidExampleFolder at sdcard
              imageStorageDir.mkdirs();
             }

             // Create camera captured image file path and name 
             File file = new File(
               imageStorageDir + File.separator + "IMG_"
                 + String.valueOf(System.currentTimeMillis()) 
                 + ".jpg");

             mCapturedImageURI = Uri.fromFile(file); 

             // Camera capture image intent
             final Intent captureIntent = new Intent(
               android.provider.MediaStore.ACTION_IMAGE_CAPTURE);

             captureIntent.putExtra(MediaStore.EXTRA_OUTPUT, mCapturedImageURI);

             Intent i = new Intent(Intent.ACTION_PICK); 
            // i.addCategory(Intent.CATEGORY_OPENABLE);
             i.setType("image/*");

             // Create file chooser intent
             Intent chooserIntent = Intent.createChooser(i, "Image Chooser");

             // Set camera intent to file chooser 
             chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS
               , new Parcelable[] { captureIntent });

             // On select image call onActivityResult method of activity
             startActivityForResult(chooserIntent, FILECHOOSER_RESULTCODE);

            }
            catch(Exception e){
             Toast.makeText(getBaseContext(), "Exception:"+e, 
               Toast.LENGTH_LONG).show();
            }

           }
     protected void onActivityResult(int requestCode, int resultCode,Intent intent) { 

          if(requestCode==FILECHOOSER_RESULTCODE)  
          {  
              if (requestCode == GALLERY_PICTURE)
                    {
                        if (resultCode == RESULT_OK) 
                        {
                            if (intent != null) 
                            {                   
                                // our BitmapDrawable for the thumbnail
                                BitmapDrawable bmpDrawable = null;

                                // try to retrieve the image using the data from the intent
                                Cursor cursor = getContentResolver().query(intent.getData(), null, null, null, null);

                                if (cursor != null) 
                                {
                                    cursor.moveToFirst();

                                    int idx = cursor.getColumnIndex(ImageColumns.DATA);
                                    String fileSrc = cursor.getString(idx);
                                    Bitmap galleryBitmap = BitmapFactory.decodeFile(fileSrc); // load preview image                                                                         
                                    galleryBitmap = Bitmap.createScaledBitmap(galleryBitmap, 200, 200, true);


                                    String filePath = Environment.getExternalStorageDirectory()
                                    .getAbsolutePath()+"/TimeChat/image/"+System.currentTimeMillis()+".jpg";

                                    //imgCamera.setRotation(0);
                                    imgCamera.setImageBitmap(galleryBitmap);
//                                  writeToFile(filePath, galleryBitmap);
                                } 
                                else 
                                {
                                    bmpDrawable = new BitmapDrawable(getResources(), intent.getData().getPath());
                                    imgCamera.setImageDrawable(bmpDrawable);
                                }
                            } 
                            else 
                            {
                                Toast.makeText(getApplicationContext(), "Cancelled", Toast.LENGTH_SHORT).show();
                            }
                        } 
                        else if (resultCode == RESULT_CANCELED) 
                        {
                            Toast.makeText(getApplicationContext(), "Cancelled", Toast.LENGTH_SHORT).show();
                        }
                    } 
                    else if (requestCode == CAMERA_REQUEST) 
                    {
                        if (resultCode == RESULT_OK) 
                        {
                            if (intent.hasExtra("data"))
                            {                   
                                // retrieve the bitmap from the intent
                                Bitmap cameraBitmap = (Bitmap) intent.getExtras().get("data");

                                    String filePath = Environment.getExternalStorageDirectory()
                                .getAbsolutePath()+"/TimeChat/image/"+System.currentTimeMillis()+".jpg";

                                // update the image view with the bitmap
                                imgCamera.setImageBitmap(cameraBitmap);
                            //  writeToFile(filePath, circleBitmap);

                            } 
                            else if (intent.getExtras() == null) {

                                Toast.makeText(getApplicationContext(), "No extras to retrieve!", Toast.LENGTH_SHORT).show();

                                BitmapDrawable thumbnail = new BitmapDrawable(getResources(), intent.getData().getPath());

                                // update the image view with the newly created drawable
                                imgCamera.setImageDrawable(thumbnail);

                            }

                        } 
                        else if (resultCode == RESULT_CANCELED) {
                            Toast.makeText(getApplicationContext(), "Cancelled", Toast.LENGTH_SHORT).show();
                        }
                    }
          }
         }


    @Override
    public void onBackPressed() {
        // TODO Auto-generated method stub
        super.onBackPressed();
        ProfilePhotoActivity.this.finish();
    }

}

解决方案

This looks like it will be a problem:

 if(requestCode==FILECHOOSER_RESULTCODE)  
          {  
              if (requestCode == GALLERY_PICTURE)

unless FILECHOOSER_RESULTCODE and GALLERY_PICTURE are the same ints then statement will never pass.