Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

app crash when launch #91

Open
OTO8056 opened this issue Dec 20, 2022 · 1 comment
Open

app crash when launch #91

OTO8056 opened this issue Dec 20, 2022 · 1 comment
Assignees
Labels
question Further information is requested

Comments

@OTO8056
Copy link

OTO8056 commented Dec 20, 2022

App crash when click btn this is my code

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
        StrictMode.setThreadPolicy(policy);
       
        PicBtn= findViewById(R.id.picBtn);
    
         launcher=
                registerForActivityResult(new ActivityResultContracts.StartActivityForResult(),
                        (ActivityResult result)->{
                            if(result.getResultCode()==RESULT_OK){
                                Uri uri=result.getData().getData();
                                // Use the uri to load the image
                            }else if(result.getResultCode()==ImagePicker.RESULT_ERROR){
                                // Use ImagePicker.Companion.getError(result.getData()) to show an error
                            }
                        });

        PicBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                {
                    launcher.launch(ImagePicker.Companion.with(MainActivity.this)
                            .crop()
                            .provider(ImageProvider.BOTH)
                            .cropOval()
                            .createIntent());
                }
            }
        });
    }

 @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        //Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        Bitmap imageBitmap = null;
        if (requestCode == CropImage.CROP_IMAGE_ACTIVITY_REQUEST_CODE) {
            CropImage.ActivityResult result = CropImage.getActivityResult(data);
            imageBitmap = BitmapFactory.decodeFile(result.getUri().getPath());
            if (resultCode == RESULT_OK) {
                switch (LAST_REQUEST_CODE) {

                    case CAR_REQUEST:
                        saveImage(imageBitmap, new File(mCurrentPhotoPath));
                        PicBtn.setImageBitmap(imageBitmap);
                        break;


                }

            } else if (resultCode == CropImage.CROP_IMAGE_ACTIVITY_RESULT_ERROR_CODE) {
                Exception error = result.getError();
            }
        } else {

            startCropActivity(Uri.fromFile(new File(mCurrentPhotoPath)));
        }
    }
@Drjacky Drjacky self-assigned this Dec 21, 2022
@Drjacky Drjacky added the question Further information is requested label Dec 21, 2022
@Drjacky
Copy link
Owner

Drjacky commented Dec 21, 2022

Please attach the logcat (crash) too.
Also, remove all StrictMode and see if you still get the crash or not. if not, it means you have not configured the StrictMode correctly (or used it incorrectly).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants