android-networking

How to return response header field to main method using Google Volley for HTTP GET request in Android / Java?

给你一囗甜甜゛ 提交于 2019-12-05 04:24:40
I'm using google volley for networking in android. I will make a http GET request and need to return a response header value. I found some answers on stack overflow to access the header fields, but don't know how to return it to my calling spot. Please have a look at my code, I put four numbers in it to explain my problem. At (1) I can print out the value which I need. Than I've tried to save it in a class attribute (2) and there is no error in the IDE. If I want to return it from there (3), I got a NullPointerException at (4). Maybe its a read before write problem there. So how can I get the

Android Find the device's ip address when it's hosting a hotspot

天大地大妈咪最大 提交于 2019-12-05 02:49:55
I need to find the device's ip address when it's hosting a hotspot. I've used this code so far : //if is using Hotspot for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) { NetworkInterface intf = en.nextElement(); if (intf.getName().contains("wlan")) { for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) { InetAddress inetAddress = enumIpAddr.nextElement(); if (!inetAddress.isLoopbackAddress() && (inetAddress.getAddress().length == 4)) { return inetAddress.getHostAddress(); } } } } This works

Unable to access Internet via WiFi from a Background service

↘锁芯ラ 提交于 2019-12-05 00:47:32
问题 I'll get straight onto some facts/figures I discovered pls help me if you've faced/solved a similar problem. I send back data every 5 minutes to a server unless the user manually toggles it Off with the help of a wakeful broadcast receiver through a intent service . Plus I get wifi locks before doing (I've tried this already without locks; doesnt work either) Now on devices sending back data from regular data networks (2G/3G/4G) this works fine but on those connected to a wifi network somehow

CONNECTIVITY_CHANGE deprecated in target of Android N

丶灬走出姿态 提交于 2019-12-04 23:03:28
I am getting warning of deprecated declaration of Broadcast Receiver. <!-- NETWORK RECEIVER... --> <receiver android:name=".utils.NetworkUtils" > <intent-filter> <action android:name="android.net.conn.CONNECTIVITY_CHANGE" /> </intent-filter> </receiver> WARNING: Declaring a broadcastreceiver for android.net.conn.CONNECTIVITY_CHANGE is deprecated for apps targeting N and higher. In general, apps should not rely on this broadcast and instead use JobScheduler or GCMNetworkManager. Is there any other way to use it without deprecated methods? I had the same problem, i did something like that. It

Any good example for working with UNKNOWN CA signed certificate(like pkcs12) in android

血红的双手。 提交于 2019-12-04 22:09:07
I am working on android application, which requires to communicate with server over ssl. Any good example to work with pkcs12 certificates in android using HttpsUrlConnection After doing some modifications to the code posted by @EpicPandaForce, i was able to successfully run the code. Changes: 1. KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance("X509"); to KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance("SunX509"); to get rid of exception: java.security.NoSuchAlgorithmException: X509 KeyManagerFactory not available 2. KeyStore keyStore = KeyStore

Peer to peer connection in android

天涯浪子 提交于 2019-12-04 21:51:07
Is there any way such that i can communicate with other android device in the same wifi network... for sharing files. Can I have list of all android device connected to same n/w? can any one refer me any api for doing that? or how can I make that thing happen?? this thing must be possible, Isn't it? I think this is possible in Android 4.0, using WiFiDirect but how that can be possible in lower level sdk's. Thank you you should take a look at this WifiP2pManager 来源: https://stackoverflow.com/questions/8741796/peer-to-peer-connection-in-android

how to reroute all IP traffic (pref. at the network layer) in Android 3.x

梦想与她 提交于 2019-12-04 21:02:15
This is specific to Android 3.0/3.1 In order to implement a cloud security layer, I would like to reroute all IP traffic destined for certain ports through my custom cloud server which would then serve up the required pages if they don't pose any threat. The reasons I would like to do this are: 1. The applications running on Android would still continue their interaction with regular requests and wouldn't require any modifications 2. Better security. It should not be possible for a user to disable/block my reroute service. Hiding my implementation in the network layer would make it difficult

Implementing Retrofit2 service interface

 ̄綄美尐妖づ 提交于 2019-12-04 15:28:13
Imagine the following scenario. I am using Retrofit as my API client and I am going to use a caching mechanism to persist some responses locally in let's say SQLite database, so some of the data is obtained only once. It seems like a perfect case to create a custom implementation for the following interface which is going to fetch the data from local database when network is not available. public interface CommentsService { @GET("posts/{postId}/comments") Call<List<Comment>> getCommentsOfPost(@Path("postId") int id); } The problem is that all service methods in retrofit2 should be wrapped in a

How to change the network state of device from source code in Android?

烂漫一生 提交于 2019-12-04 14:53:51
问题 I am trying to change the network state of the device from the source code. I observed that there is a permission to grant to the applications for changing the network state i.e., CHANGE_NETWORK_STATE. But I am not able to find any example or code that can change the network state of a device. Please let me know if anyone knows or have an example to change the network state of a device. Regards, SSuman185 回答1: This code is working. I got it from here. private void setMobileDataEnabled(Context

how to use retrofit 2 to send file and other params together

天涯浪子 提交于 2019-12-04 13:42:31
I am looking for an example how could I send file and other params together to server. I have to send server JSON which { "title": "title", "file": "uploaded file instance", "location": { "lat": 48.8583, "lng": 2.29232, "place": "Eiffel Tower" } } How could I create Retrofit to handle this case? If file is a string I know how to handle this. If file is File object I have no idea how to do this. Use gson and create a model class for the location. Add the following dependencies to your build.gradle . compile 'com.squareup.retrofit2:converter-gson:2.0.0' compile 'com.google.code.gson:gson:2.5'