java – How to share image in android studio for all APIs?

I need your help, I am uploading apps to the Huawei appgallery store, and the person who is reviewing my app tells me that my application stops when he presses the share button.
When I use my app there is no problem, but I think this can happen through the API.
How can I improve or correct this code?
I hope someone can help me. Thanks !

public class MainActivity extends AppCompatActivity {

    Button btn_shareimage;

    //Share Image
    private void shareimage(Integer image){
        Bitmap icon = BitmapFactory.decodeResource(getResources(), image);
        Intent share = new Intent(Intent.ACTION_SEND);

        ContentValues values = new ContentValues();
        values.put(MediaStore.Images.Media.TITLE, "title");
        values.put(MediaStore.Images.Media.MIME_TYPE, "image/jpeg");
        Uri uri = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
        OutputStream outstream;
        try {
            outstream = getContentResolver().openOutputStream(uri);
            icon.compress(Bitmap.CompressFormat.JPEG, 100, outstream);
        } catch (Exception e) {
        share.putExtra(Intent.EXTRA_STREAM, uri);
        startActivity(Intent.createChooser(share, "Share Image"));

    protected void onCreate(Bundle savedInstanceState) {

        textView = findViewById(;
        button = findViewById(;

        btn_shareimage = (Button) findViewById(;
                btn_shareimage.setOnClickListener(new View.OnClickListener() {
                    public void onClick(View view) {

                        //Share image