Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8860453
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T15:16:13+00:00 2026-06-14T15:16:13+00:00

I ran into a problem of this type – when I try to download

  • 0

I ran into a problem of this type – when I try to download the favicon of some sites, you come across a redirect (like google.com / favicon.ico -> http://www.google.com / favicon.ico). In this case, my code does not save the image. I wonder whether it is possible to know whether the page is redirected, or how to change my code to work around this obstacle. I hope for your help.

 @Override
    protected Boolean doInBackground(Void...param) {
        Log.d("url in NetworkTask", url);
        HttpGet httpGet = new HttpGet(url);
        AndroidHttpClient httpClient = AndroidHttpClient
                                        .newInstance("Android");
        HttpResponse httpResponse = null;
        try {
            httpResponse = httpClient.execute(httpGet);                       
        } catch (IOException e) {
            e.printStackTrace();                
        }
        if(httpResponse!=null) 
            primaryCodeStatus = httpResponse.getStatusLine()
                .getStatusCode();
        else Log.d("httpResponse", "NULL");            
        if(primaryCodeStatus != 0){             
            try {
                urlFavIcon = new URL(url).getProtocol()
                        +"://"
                        +new URL(url).getHost()
                        +"/favicon.ico";
                fileName = new URL(url).getHost()+"(FAVICON).jpg";
                System.out.println(urlFavIcon);
            } catch (MalformedURLException e) {
                e.printStackTrace();
            }
            if(!(urlFavIcon.equals(""))){                   
                httpGet = new HttpGet(urlFavIcon);
                try {
                    httpResponse = httpClient.execute(httpGet);
                } catch (IOException e) {
                    e.printStackTrace();
                }                   
                try {
                    is = (java.io.InputStream)
                                        httpResponse
                                        .getEntity()
                                        .getContent();
                } catch (IllegalStateException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }                   
            }
            httpClient.close();
            Log.d("START SERVICE", "monitor url: "+url);                                        
            return true;
        } 
        else return false;             
    }

    @Override
    public void onPostExecute(Boolean param){
        if(param){
            Bitmap siteIcon = BitmapFactory.decodeStream(is);
            String path = Environment.getExternalStorageDirectory().getPath()+"/"; 
            System.out.println(Environment.getExternalStorageDirectory().canWrite());
            File fileFavIcon = null;
            fileFavIcon = new File(path, fileName);
            if(fileFavIcon != null && siteIcon != null){
                try {
                    FileOutputStream fOS = new FileOutputStream(fileFavIcon);
                    siteIcon.compress(Bitmap.CompressFormat.PNG, 100, fOS);
                    fOS.flush();
                    fOS.close();
                } catch (FileNotFoundException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

            getActivity()
                .startService(new Intent(getActivity(), ExService.class)
                .putExtra("UrlBox", new UrlBoxHelper(new UrlBox(url,
                                            60000))));  
            FragmentDialogAddNewUrlConectActivity conectActivity =
                    (FragmentDialogAddNewUrlConectActivity) getActivity();          
                conectActivity
                    .fragmentDialogClickButtonListener(url,
                                                    drawableFavIconUrl);                                                
        }               
        else {              
            Toast toastInfo = Toast
                    .makeText(getActivity().getApplicationContext(),
                    "This link does not exist page",
                    Toast.LENGTH_LONG);
            toastInfo.setGravity(Gravity.TOP, 0, 0);
            toastInfo.show();               
        }

    }

EDIT

Here he wrote that solved my problem:

httpGet = new HttpGet(urlFavIcon);
HttpParams params = new BasicHttpParams();
params.setParameter("http.protocol.handle-redirects",false);
httpGet.setParams(params);
httpResponse = httpClient.execute(httpGet);
Header locationHeader = httpResponse.getFirstHeader("location");
if(locationHeader != null){
   System.out.println(locationHeader.getValue());// locationHeader.getValue() get new link(redirect)
   urlFavIcon = locationHeader.getValue();
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T15:16:14+00:00Added an answer on June 14, 2026 at 3:16 pm

    You should check the status code of your http request. The 3xx codes represents redirections. So you can react to them properly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I ran into a problem with some C code like this: struct SomeType {
Never ran into this problem with jQuery before. I have the following: $(document).ready(function() {
I ran into this problem and I cant solve it. Basically Im making an
All, I ran into this problem where for a UITextField that has secureTextEntry=YES, I
I ran into this concurrency problem which I've been scratching my head for several
I ran into a problem using Springsource Tool Suite when writing some groovy scripts
So I ran into this exact problem: http://www.vistax64.com/powershell/273120-bug-when-using-namespace-parameter-new-webserviceproxy.html The gist of the issue is
I'm fairly new to Mvc and ran into a problem try to use an
today I ran into this problem which really bugs me, as almost the code
I ran into this problem using EF4 and a self-referential table (implementing an adjacency

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.