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

return error "Image provider can not be null"? Any idea... #99

Open
sceddd opened this issue May 30, 2023 · 0 comments
Open

return error "Image provider can not be null"? Any idea... #99

sceddd opened this issue May 30, 2023 · 0 comments

Comments

@sceddd
Copy link

sceddd commented May 30, 2023

Im try to get image from lib or camera but it's return error "Image provider can not be null". Any idea...

public class MainActivity extends AppCompatActivity {

    private ImageButton temp;
    private Uri image_uri;
    ImageButton inputImg;
    ImageView outputImg;
    Button submit;
    private ProgressBar prg;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        prg = findViewById(R.id.progressbar);
        inputImg = findViewById(R.id.dadImg);
        outputImg = findViewById(R.id.momImg);
        submit = findViewById(R.id.submit);
        inputImg.setOnClickListener(this::onImageClick);
        submit.setOnClickListener(this::postData);
    }

    public void postData(View v) {
        ...
    }

    public void onImageClick(View v) {
        Intent imagePicker = ImagePicker.Companion.with(MainActivity.this)
                .maxResultSize(1080, 1080, true).provider(ImageProvider.BOTH).createIntent();
        launcher.launch(imagePicker);
    }

    ActivityResultLauncher<Intent> launcher =
            registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), (ActivityResult result) -> {
                if (result.getResultCode() == RESULT_OK) {
                    Uri uri = result.getData().getData();
                    inputImg.setImageURI(uri);
                    // Use the uri to load the image
                } else if (result.getResultCode() == ImagePicker.RESULT_ERROR) {
                    ImagePicker.Companion.getError(result.getData());
                }
            });
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant