0

In RoomDetailFragment.kt I already passed an activity and to the java file and tried to pass that with my URI "Dicom-path" from my mobile phone. There is no error but I don't know how to pass it may be in another way? so I thought intent.putExtra to give it to my java class "dicomimageview.java". It runs and works till my dicomimageview at the end from the code of onCreate. It crashed after this and just showed me a red rectangle. After this, I added the new Intent in onCreate at dicomimageview. Is he even passing the file path or is it just for the new activity and not getting access to my dicompath? Because I need to get for the new activity the code with on protected void onActivityResult ( int requestCode, int resultCode, Intent data). It will transform the file into an image and can display it. But it can't even start the activity so it just showed me a white screen and doesn't go to the next activity for onActivityResult. I hope someone can help me.

Update PROBLEM is now he is showing me just a red picture -> I think it is a ACTIVITY Problem but i have to learn how to create a new activity in dicomImageViewer.java -> still failed enter image description here

RoomDetailFragment.kt

private fun startOpenFileIntent(action: RoomDetailViewEvents.OpenFile) {

       val uri1 = action.uri.toString()
       val dicom_ = ".DCM"
       if (action.mimeType == MimeTypes.Apk) {
           installApk(action)
       }

           else if (uri1.contains(dicom_)) {

           activity?.let {

               val intent2 = Intent(it, dicomImageView::class.java).apply {
                   addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_ACTIVITY_NEW_TASK)
                   setDataAndType(action.uri, dicom_)

               }
               startActivity(intent2)
           }
               }
   else {
               openFile(action)
           }
       }

dicomImageView.java


public class dicomImageView extends AppCompatActivity {
    // First thing: load the Imebra library
    private ImageView mImageView; // Used to display the image
    private TextView mTextView;  // Used to display the patient name

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        System.loadLibrary("imebra_lib");

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // We will use the ImageView widget to display the DICOM image
        mImageView = findViewById(R.id.imageView);
        mTextView = findViewById(R.id.textView);

        ActivityResultLauncher<Intent> someActivityResultLauncher = registerForActivityResult(
                new ActivityResultContracts.StartActivityForResult(),
                result -> {
                    if (result.getResultCode() == Activity.RESULT_OK) {
                        // There are no request codes

                        Intent data1 = result.getData();
                        doSomeOperations(data1);
                    }
                });
    }

    public void doSomeOperations(Intent intent) {

        Uri selectedfile = intent.getData();

        CodecFactory.setMaximumImageSize(8000, 8000);
        InputStream stream = null;
        try {
            stream = getContentResolver().openInputStream(selectedfile);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }

        // The usage of the Pipe allows to use also files on Google Drive or other providers
        PipeStream imebraPipe = new PipeStream(32000);

        // Launch a separate thread that read from the InputStream and pushes the data
        // to the Pipe.
        Thread pushThread = new Thread(new PushToImebraPipe(imebraPipe, stream));
        pushThread.start();

        // The CodecFactory will read from the Pipe which is feed by the thread launched
        // before. We could just pass a file name to it but this would limit what we
        // can read to only local files
        DataSet loadDataSet = CodecFactory.load(String.valueOf(intent));


        // Get the first frame from the dataset (after the proper modality transforms
        // have been applied).
        Image dicomImage = loadDataSet.getImageApplyModalityTransform(0);

        // Use a DrawBitmap to build a stream of bytes that can be handled by the
        // Android Bitmap class.
        TransformsChain chain = new TransformsChain();

        if (ColorTransformsFactory.isMonochrome(dicomImage.getColorSpace())) {
            VOILUT voilut = new VOILUT(VOILUT.getOptimalVOI(dicomImage, 0, 0, dicomImage.getWidth(), dicomImage.getHeight()));
            chain.addTransform(voilut);
        }
        DrawBitmap drawBitmap = new DrawBitmap(chain);
        Memory memory = drawBitmap.getBitmap(dicomImage, drawBitmapType_t.drawBitmapRGBA, 4);

        // Build the Android Bitmap from the raw bytes returned by DrawBitmap.
        Bitmap renderBitmap = Bitmap.createBitmap((int) dicomImage.getWidth(), (int) dicomImage.getHeight(), Bitmap.Config.ARGB_8888);
        byte[] memoryByte = new byte[(int) memory.size()];
        memory.data(memoryByte);
        ByteBuffer byteBuffer = ByteBuffer.wrap(memoryByte);
        renderBitmap.copyPixelsFromBuffer(byteBuffer);

        // Update the image
        mImageView.setImageBitmap(renderBitmap);
        mImageView.setScaleType(ImageView.ScaleType.FIT_CENTER);

        // Update the text with the patient name
        mTextView.setText(loadDataSet.getPatientName(new TagId(0x10, 0x10), 0, new PatientName("Undefined", "", "")).getAlphabeticRepresentation());

    }
}




activity_dicom_image_view.xml

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".features.home.room.detail.dicomImageView">

    <LinearLayout
        android:layout_width="368dp"
        android:layout_height="495dp"
        android:layout_margin="0dp"
        android:gravity="center_vertical|fill_vertical|center_horizontal|fill_horizontal"
        android:orientation="vertical"
        android:padding="0dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHeight_default="percent"
        app:layout_constraintHeight_percent="100"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintWidth_default="percent"
        app:layout_constraintWidth_percent="100">

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_margin="0dp"
        android:layout_weight="1"
        android:adjustViewBounds="false"
        android:contentDescription="@string/image_description"
        android:cropToPadding="false"
        android:padding="0dp"
        app:srcCompat="@color/colorprimary" />

    <TextView
        android:id="@+id/textView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1" />
    </LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

also in the application, the activity is added in AndroidManifest.xml

<application
        android:name=".VectorApplication"
        android:allowBackup="false"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:networkSecurityConfig="@xml/network_security_config"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.Vector.Light"
        tools:replace="android:allowBackup">
        <activity
            android:name=".features.home.room.detail.dicomImageView"
            android:exported="true" />
        <!-- No limit for screen ratio: avoid black strips -->
        <meta-data
SuperAfsd
  • 3
  • 8

1 Answers1

0

Edit:

Also inside your called activity you should be able to grab the intent from the calling activity with this inside your onCreate in dicomImageView.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    ...
    Intent intent = getIntent();
    ...
}

Looks like your syntax might be incorrect.

Try changing:

val intent = Intent(context,dicomImageView::class.java)
intent.putExtra("Dicomimage",neu[0])
startActivity(intent)
}

To:

val intent = Intent(context,dicomImageView::class.java).apply {
    putExtra("Dicomimage",neu[0])
}
startActivity(intent)

See: https://developer.android.com/training/basics/firstapp/starting-activity#BuildIntent

luckyging3r
  • 3,047
  • 3
  • 18
  • 37
  • yes i already pass it thourgh but now i have a problem in my java file -> from RoomDetailFragment.kt -> to dicomimageview.java (onCreate) but it just showed me a white screen.. it doesn't go in debuger to my creation of dicom image.. – SuperAfsd Sep 21 '21 at 19:23
  • because you're instantly calling `startActivity()` in your `onCreate` inside dicomImageView.java – luckyging3r Sep 21 '21 at 19:27
  • `onActivityResult` is only called once android returns back this activity – luckyging3r Sep 21 '21 at 19:30
  • so does something else can do for calling the creation of this kind of activity or are they other ways to create new activity? – SuperAfsd Sep 21 '21 at 19:32
  • you never actually grab the intent extra data from RoomDetailFragment.kt – luckyging3r Sep 21 '21 at 19:37
  • look at my code above i changed it -> to grab the extra of intent is that better? – SuperAfsd Sep 21 '21 at 19:41
  • i don't know if i can can add a new activity for the creation or I should use just my function in my new edited code above – SuperAfsd Sep 21 '21 at 19:43
  • If you need to access the "Dicomimage" extra data you need to grab it inside of your onCreate method of dicomImageView.java with `Intent theIntent = getIntent();`. Then you can add that to the ACTION_GET_CONTENT intent you were calling before you edited your code. – luckyging3r Sep 21 '21 at 19:47
  • Intent intent = getIntent(); String data = intent.ACTION_GET_CONTENT; you mean like this ? it runs until my inputstream and gives error OPEN FAILED: ENOENT (NO SUCH FILE OR DIRECTORY) – SuperAfsd Sep 21 '21 at 19:54
  • Try looking at this: https://stackoverflow.com/a/36129285/5184092 . I'm not sure anymore what you're fully trying to do. Sounds like you're trying to grab a specific file from your system using the ACTION_GET_CONTENT. You might need to look at getting the full URI if you're not already – luckyging3r Sep 21 '21 at 19:59
  • 1
    i already picked it on fileselector -> the file is in my chat -> now I am clicking on my data .. it is a dicomfile for example mrBrain.dcm -> I clicked and I want to open that file -> from RoomDetailFragment -> to my dicomimageview -> I passed it through a uri file and now it can't open the inputstream.. i think that the full URI is broke .. i will see on your link – SuperAfsd Sep 21 '21 at 20:02
  • it does not work.. i don't know it doesn't give me the primission for the file provider and I already wanted to add pathUtil – SuperAfsd Sep 22 '21 at 07:32
  • 1
    solved the problem bro thank for thehelps <3 – SuperAfsd Sep 28 '21 at 18:44