0

I wanted to make a program that would output a image fron the internet by a link to the screen, but the image either appears as a cropped strip, or does not appear at all. I will be very grateful for you help code

package com.example.myapplication2;

import androidx.appcompat.app.AppCompatActivity;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;

public class MainActivity extends AppCompatActivity {
    private EditText s;
    private TextView d;
    private Button button1;
    private URL link;
     private InputStream j;
    private Bitmap bitmap;
    private ImageView image4;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        d = findViewById(R.id.textView12);
        s = findViewById(R.id.editText1);
        button1 = findViewById(R.id.button1);
       image4 = findViewById(R.id.imageView3);
    }

    @Override
    protected void onResume() {
        super.onResume();
    }
    public void onClickStart(View view){
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    link = new URL(s.getText().toString());
                    try {
                        j = (InputStream)link.getContent();
                    }
                    catch (IOException e){
                        d.setText("fail");
                    }
                }
                catch (MalformedURLException e){
                    d.setText("fail");
                }
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        bitmap = BitmapFactory.decodeStream(j);
                        image4.setImageBitmap(bitmap);
                    }
                });
            }
        }).start();
    }
}

enter image description here enter image description here

It is possible in incorrect handling of the permission or file type, I would appreciate your help

Newtilous
  • 1
  • 1
  • Glide is a popular image library. https://stackoverflow.com/questions/45232608/how-to-load-image-into-imageview-from-url-using-glide-v4-0-0rc1 – JonR85 Jan 13 '23 at 21:26

0 Answers0