Trusting all certificates with okHttp

Just in case anyone falls here, the (only) solution that worked for me is creating the OkHttpClient like explained here. Here is the code: private static OkHttpClient getUnsafeOkHttpClient() { try { // Create a trust manager that does not validate certificate chains final TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() { @Override public void … Read more

Broadcast receiver for checking internet connection in android app

Answer to your first question: Your broadcast receiver is being called two times because You have added two <intent-filter> Change in network connection : <action android:name=”android.net.conn.CONNECTIVITY_CHANGE” /> Change in WiFi state: <action android:name=”android.net.wifi.WIFI_STATE_CHANGED” /> Just use one: <action android:name=”android.net.conn.CONNECTIVITY_CHANGE” />. It will respond to only one action instead of two. See here for more information. … Read more

Android check internet connection [duplicate]

This method checks whether mobile is connected to internet and returns true if connected: private boolean isNetworkConnected() { ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); return cm.getActiveNetworkInfo() != null && cm.getActiveNetworkInfo().isConnected(); } in manifest, <uses-permission android:name=”android.permission.ACCESS_WIFI_STATE” /> <uses-permission android:name=”android.permission.ACCESS_NETWORK_STATE” /> Edit: This method actually checks if device is connected to internet(There is a possibility it’s connected to … Read more

Comparison of Android networking libraries: OkHTTP, Retrofit, and Volley [closed]

I’m hoping someone can provide some concrete examples of best use cases for each. Use Retrofit if you are communicating with a Web service. Use the peer library Picasso if you are downloading images. Use OkHTTP if you need to do HTTP operations that lie outside of Retrofit/Picasso. Volley roughly competes with Retrofit + Picasso. … Read more

How to check internet access on Android? InetAddress never times out

If the device is in airplane mode (or presumably in other situations where there’s no available network), cm.getActiveNetworkInfo() will be null, so you need to add a null check. Modified (Eddie’s solution) below: public boolean isOnline() { ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo netInfo = cm.getActiveNetworkInfo(); return netInfo != null && netInfo.isConnectedOrConnecting(); } Also add … Read more

How can I fix ‘android.os.NetworkOnMainThreadException’?

NOTE : AsyncTask was deprecated in API level 30. AsyncTask | Android Developers This exception is thrown when an application attempts to perform a networking operation on its main thread. Run your code in AsyncTask: class RetrieveFeedTask extends AsyncTask<String, Void, RSSFeed> { private Exception exception; protected RSSFeed doInBackground(String… urls) { try { URL url = … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)