mardi 30 janvier 2018

Android Only upload image if an image is selcted

I use following Code to select an image from gallery and display it with an ImageView:

@Override
    protected void onActivityResult(int RC, int RQC, Intent I) {

        super.onActivityResult(RC, RQC, I);

        if (RC == 1 && RQC == RESULT_OK && I != null && I.getData() != null) {

            Uri uri = I.getData();

            try {

                bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), uri);

                imageView.setImageBitmap(bitmap);

            } catch (IOException e) {

                e.printStackTrace();
            }
        }
    }

Currently, with the method ImageUploadToServerFunction() the upload will be started, also if no image is selected. Finally the app crashes.

My question: What can I do, not to start the upload and post an Toast if there is no image selected?

if (imageView == ???) {
            ImageUploadToServerFunction();
        } else {
            Toast.makeText(MainActivity.this, "No image selected!", Toast.LENGTH_LONG).show();
        }

Aucun commentaire:

Enregistrer un commentaire