Problem calling method on AndroidStudio

0

I want to call a method in Android Studio after the user selects an option. However, I have tried in several ways through getItemId (), however, I call the method and nothing happens. Will it be a problem in the takeScreenshot method, or should I use a new Intent? If so, how could I do this?

          @Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == R.id.main_add_sticker) {
        Intent intent = new Intent(this, StickerSelectActivity.class);
        startActivityForResult(intent, SELECT_STICKER_REQUEST_CODE);
        return true;
    } else if (item.getItemId() == R.id.main_remove_sticker) {
        motionView.deletedSelectedEntity();
    } else if (item.getItemId() == R.id.main_change_image) {
        Intent i = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI);
        startActivityForResult(Intent.createChooser(i, "Selecione uma imagem"), PICK_IMAGE);
    } else if (item.getItemId() == R.id.main_save_croqui) {
        takeScreenshot();
    }
    return super.onOptionsItemSelected(item);
}


public void takeScreenshot(){
    Date now = new Date();
    android.text.format.DateFormat.format("yyyy-MM-dd_hh:mm:ss", now);

    try {
        String mPath = Environment.getExternalStorageDirectory().toString()+"/" + now + ".jpg";

        View v1 = getWindow().getDecorView().getRootView();
        v1.setDrawingCacheEnabled(true);
        Bitmap bitmap = Bitmap.createBitmap(v1.getDrawingCache());

        File imageFile = new File(mPath);
        FileOutputStream outputStream = new FileOutputStream(imageFile);
        int quality = 100;
        bitmap.compress(Bitmap.CompressFormat.JPEG, quality, outputStream);
        outputStream.flush();
        outputStream.close();

        openScreenshot(imageFile);



    } catch (Throwable e){
        e.printStackTrace();
    }
}

public void openScreenshot (File imageFile){
    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_VIEW);
    Uri uri = Uri.fromFile(imageFile);
    intent.setDataAndType(uri, "image/");
    startActivity(intent);

}
    
asked by anonymous 03.06.2018 / 03:45

0 answers