android-networking

Trusting all certificates with okHttp

半城伤御伤魂 提交于 2019-11-26 19:22:28
For testing purposes, I'm trying to add a socket factory to my okHttp client that trusts everything while a proxy is set. This has been done many times over, but my implementation of a trusting socket factory seems to be missing something: class TrustEveryoneManager implements X509TrustManager { @Override public void checkClientTrusted(java.security.cert.X509Certificate[] chain, String authType) throws CertificateException { } @Override public void checkServerTrusted(java.security.cert.X509Certificate[] chain, String authType) throws CertificateException { } @Override public java.security.cert

Android, How to handle change in network (from GPRS to Wi-fi and vice-versa) while polling for data

杀马特。学长 韩版系。学妹 提交于 2019-11-26 16:02:20
问题 I use DefaultHttpClient and HttpGet to poll data from server. Now, say a user was in Wi-fi network and moves out of the room. So the phone automatically starts using the 3G network. Are there any call-backs for such change, and how should I handle such changes. Should I start polling again or does the OS take care to make the changes appropriately 回答1: You can set up a Receiver in your manifest: <receiver android:name=".NetworkChangeReceiver" android:label="NetworkChangeReceiver"> <intent

Volley and AsyncTask

邮差的信 提交于 2019-11-26 15:43:32
问题 I read a post about Volley and I know it's great networking library. But I couldn't understand one thing. All requests are Async Task or not? When I want to send asyncTask request using Volley do I need put Volley request in AsyncTask? or should I just call Volley Request if it is already AsyncTask request? private class MyClass extends AsyncTask<String, Void, String> { @Override protected String doInBackground(String... params) { // do Volley request } } Is this right approach? 回答1: You don

How to determine if network type is 2G, 3G or 4G

守給你的承諾、 提交于 2019-11-26 14:13:16
I have an indicator on my application to display the network type (2G or 3G or 4G) but after getting the network type, how do I know what speed category it should be in? I know how to detect the network type: private TelephonyManager telephonyManager; telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); CurrentNetworkType = telephonyManager.getNetworkType(); Given the possible return values: // public static final int NETWORK_TYPE_1xRTT // Since: API Level 4 // Current network is 1xRTT // Constant Value: 7 (0x00000007) // // public static final int NETWORK_TYPE

Intent action for network events in android sdk

孤街浪徒 提交于 2019-11-26 12:59:32
I need to receive broadcasts for network actions like network connected, disconnected etc. I am using a broadcast receiver for this purpose. Can anyone please tell me which intent action I need to capture for network events, right now as per my search on internet I am using android.net.ConnectivityManager.CONNECTIVITY_ACTION . Here is my broadcast receiver class: import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; public class NetworkStateReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { /

Get response status code using Retrofit 2.0 and RxJava

混江龙づ霸主 提交于 2019-11-26 10:07:36
问题 I\'m trying to upgrade to Retrofit 2.0 and add RxJava in my android project. I\'m making an api call and want to retrieve the error code in case of an error response from the server. Observable<MyResponseObject> apiCall(@Body body); And in the RxJava call: myRetrofitObject.apiCall(body).subscribe(new Subscriber<MyResponseObject>() { @Override public void onCompleted() { } @Override public void onError(Throwable e) { } @Override public void onNext(MyResponseObject myResponseObject) { //On

Google Cloud Messaging - messages sometimes not received until network state changed

大憨熊 提交于 2019-11-26 08:03:36
问题 While working on a little project that integrates with GCM, I\'ve stumbled across a bit of a strange issue. Some times when I start watching the log to see if messages are received, messages do not appear to be coming through until I have changed the network state (I.E. originally on WiFi, if I turn off WiFi and move to Mobile Data, the messages arrive fine). After I\'ve changed the network state, messages start to arrive perfectly fine, and the same applies once I change the network state

Trusting all certificates with okHttp

馋奶兔 提交于 2019-11-26 06:57:06
问题 For testing purposes, I\'m trying to add a socket factory to my okHttp client that trusts everything while a proxy is set. This has been done many times over, but my implementation of a trusting socket factory seems to be missing something: class TrustEveryoneManager implements X509TrustManager { @Override public void checkClientTrusted(java.security.cert.X509Certificate[] chain, String authType) throws CertificateException { } @Override public void checkServerTrusted(java.security.cert

Get my wifi ip address Android

白昼怎懂夜的黑 提交于 2019-11-26 06:30:25
问题 How can I get the ip address of my phone when it is connected under wifi? I found a method here but it returns something like 24.182.239.255 even if I\'m under wifi and I expect something like 192.168.1.10. I\'d like something like: if (you are under wifi) String ip4 = getWifiIP() else String ip4 = getIPAddress with the method linked before Many thanks! 回答1: If you would like to get the private IP address of your device when connected to Wi-Fi, you can try this. WifiManager wifiMgr =

Volley Android Networking Library

江枫思渺然 提交于 2019-11-26 06:10:19
问题 I have few questions around using Volley in my projects: Can this library be used in any Java project or just Android? I see multiple branches here and no documentation on which branch is to start with. Which branch should I use to start with? How do you integrate this library in your own project? What approach is better: Make Volley as a standalone library project and spin a jar and put it in your project or copy the all source code inside your project? 回答1: $ git clone https://android