DownloadIng full HTML of a website in Android Studio

-2
package com.learning.guessthecelebrity;

import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class MainActivity extends AppCompatActivity {


    ExecutorService executorService;
    URL url;
    HttpURLConnection httpURLConnection;
    InputStream inputStream;
    InputStreamReader reader;
    public String result;


        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
         executorService = Executors.newSingleThreadExecutor();
        executorService.execute(new Runnable() {
            @Override
            public void run() {
                try {
                    url = new URL("https://www.hollywood.com/top-celebs-100/");
                    httpURLConnection = (HttpURLConnection) url.openConnection();
                    inputStream = httpURLConnection.getInputStream();
                    reader = new InputStreamReader(inputStream);
                    int data = reader.read();

                    while(data!=-1) {
                        char current = (char) data;
                        result+=current;
                        data = reader.read();

                    }
                } catch (MalformedURLException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                } catch (Exception e) {
                    e.printStackTrace();
                } finally {
                    if (httpURLConnection==null)
                        httpURLConnection.disconnect();
                }

                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        Log.i("Result", result);
                    }
                });
            }
        });
}
}

When i run this code only a few lines of the HTML of website is downloaded and not the whole.

This is the logcat.

2021-04-10 19:58:49.584 25074-25074/? I/essthecelebrit: Late-enabling -Xcheck:jni
2021-04-10 19:58:49.722 25074-25074/? E/essthecelebrit: Unknown bits set in runtime_flags: 0x28000
2021-04-10 19:58:49.946 25074-25074/? E/RefClass: java.lang.reflect.InvocationTargetException
2021-04-10 19:58:50.107 25074-25074/? I/PswFrameworkFactoryImpl: get feature:IPswScreenModeFeature
2021-04-10 19:58:50.367 25074-25074/com.learning.guessthecelebrity E/PswScreenModeFeature: failed to get oppposcreenmode service:binder null
2021-04-10 19:58:50.367 25074-25074/com.learning.guessthecelebrity E/PswScreenModeFeature: failed to get oppposcreenmode service:interface null.
2021-04-10 19:58:51.150 25074-25074/com.learning.guessthecelebrity W/essthecelebrit: Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (greylist, reflection, allowed)
2021-04-10 19:58:51.152 25074-25074/com.learning.guessthecelebrity W/essthecelebrit: Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (greylist, reflection, allowed)
2021-04-10 19:58:51.508 25074-25270/com.learning.guessthecelebrity D/NetworkSecurityConfig: No Network Security Config specified, using platform default
2021-04-10 19:58:51.510 25074-25270/com.learning.guessthecelebrity I/DpmTcmClient: RegisterTcmMonitor from: $Proxy0
2021-04-10 19:58:51.536 25074-25074/com.learning.guessthecelebrity D/ColorViewRootUtil: initSwipState, isDisplayCompatApp false
2021-04-10 19:58:51.537 25074-25074/com.learning.guessthecelebrity D/ColorViewRootUtil: mScreenHeight 1600, mScreenWidth 720
2021-04-10 19:58:51.545 25074-25074/com.learning.guessthecelebrity D/WindowManager: Add to mViews: DecorView@2b8809[MainActivity], this = android.view.WindowManagerGlobal@5f1da0e,pkg= com.learning.guessthecelebrity
2021-04-10 19:58:51.647 25074-25074/com.learning.guessthecelebrity I/Choreographer: Skipped 4 frames!  The application may be doing too much work on its main thread.
2021-04-10 19:58:51.724 25074-25172/com.learning.guessthecelebrity I/AdrenoGLES: QUALCOMM build                   : ca71482, Ia11ce2d146
    Build Date                       : 09/08/20
    OpenGL ES Shader Compiler Version: EV031.27.05.04
    Local Branch                     : 
    Remote Branch                    : refs/tags/AU_LINUX_ANDROID_LA.UM.8.11.R1.10.00.00.576.026
    Remote Branch                    : NONE
    Reconstruct Branch               : NOTHING
2021-04-10 19:58:51.724 25074-25172/com.learning.guessthecelebrity I/AdrenoGLES: Build Config                     : S P 8.0.12 AArch64
2021-04-10 19:58:51.736 25074-25172/com.learning.guessthecelebrity I/AdrenoGLES: PFP: 0x016ee187, ME: 0x00000000
2021-04-10 19:58:51.880 25074-25172/com.learning.guessthecelebrity W/Gralloc3: mapper 3.x is not supported
2021-04-10 19:58:52.214 25074-25074/com.learning.guessthecelebrity I/Choreographer: Skipped 32 frames!  The application may be doing too much work on its main thread.
2021-04-10 19:58:52.301 25074-25074/com.learning.guessthecelebrity I/Choreographer: Skipped 4 frames!  The application may be doing too much work on its main thread.
2021-04-10 19:58:52.311 25074-25074/com.learning.guessthecelebrity D/ColorViewRootUtil: initSwipState, isDisplayCompatApp false
2021-04-10 19:58:52.313 25074-25074/com.learning.guessthecelebrity D/ColorViewRootUtil: mScreenHeight 1600, mScreenWidth 720
2021-04-10 19:58:55.375 25074-25171/com.learning.guessthecelebrity I/essthecelebrit: Waiting for a blocking GC ProfileSaver
2021-04-10 19:58:55.384 25074-25171/com.learning.guessthecelebrity I/essthecelebrit: WaitForGcToComplete blocked ProfileSaver on ClassLinker for 9.897ms
2021-04-10 19:58:55.395 25074-25171/com.learning.guessthecelebrity I/essthecelebrit: ProcessProfilingInfo new_methods=826 is saved saved_to_disk=1 resolve_classes_delay=5000
2021-04-10 19:58:56.649 25074-25089/com.learning.guessthecelebrity I/essthecelebrit: Background concurrent copying GC freed 1250(64KB) AllocSpace objects, 937(53MB) LOS objects, 25% free, 69MB/93MB, paused 89us total 102.810ms
2021-04-10 19:59:09.352 25074-25074/com.learning.guessthecelebrity I/Result: null<!doctype html

The end few lines are the HTML of website which i have removed. I accessed INTERNET permission also in AndroidManifest.xml. Tried using AsyncDownload <String, Void, String also but doesn't work and also its depricated now. I am pretty sure this problem is not because of my Internet connection as i am using a broadband so this is a problem of my code.

Please help me with this i am a beginner.

java
android
android-studio
executorservice
chrome-app-developer-tool
asked on Stack Overflow Apr 10, 2021 by Amitesh Anand • edited Apr 11, 2021 by Amitesh Anand

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0