I am making a large app, and I am kind of stuck (actually have no time right now to grasp my head over it). This is my problem.
I am loading bunch of URL images over Glide in a primitive array (actually it's a String so I'm not sure if it's primitive or not), but its String[] array = {};
These links are shown inside of activity in gridview (less important). What I want is to check if link is valid. If it's not valid to kick an array member out.
public String[] checkingLinkValidation(String[] array) {
ArrayList<String> newArrayList = new ArrayList<>( );
String[] newArray = new String[newArrayList.size( )];
for (String s : array) {
if (Patterns.WEB_URL.matcher( s ).matches( ) && !s.equals( "" )) {
if(URLUtil.isValidUrl( s )){
newArrayList.add( s );
}
}
/**
* Nastaviti raditi na ovome. moram izbaciti link koji ne valja
*/
try{
HttpURLConnection httpURLConnection = (HttpURLConnection) new URL( s ).openConnection();
httpURLConnection.setRequestMethod( "HEAD" );
httpURLConnection.setConnectTimeout( 2000 );
httpURLConnection.setReadTimeout( 2000 );
if(httpURLConnection.getResponseCode() == HttpURLConnection.HTTP_OK){
newArrayList.add( s );
}
}catch (Exception e){
Log.d( "HTTPURLConnection check if exists", "Error type: "+e.getMessage() );
}
newArray = newArrayList.toArray( newArray );
}
return newArray; }
Problem is, program is not able to reach these links. I get exception.getMessage()
->
01-29 18:44:17.799 5705-5705/com.mario.restaurantcroatia I/System.out: (HTTPLog)-Static: isSBSettingEnabled false
x20, because there are 20 links. What could come as a clue is, all there links are loaded into an array as String over a sharedPreferences. It's also worth to mention, links are working just fine if it does not go over this method and they go directly into an array. All pictures are fine. My goal is to kick out expired links after some time.
Hope I made myself clear. Anyone have any clue why the links can't go thrue this method?