android-networking

Send data through wifi (no internet) when mobile data on

梦想的初衷 提交于 2019-12-03 04:35:11
问题 I'm developing and application that connects to a hardware device through wifi (generated by the device) and send data to it through a socket connection. The problem is that when mobile data (3G/4G) is activated android tries to send the data through it instead of sending it through the wifi generated by the device, because because the wifi has no internet connection. I was thinking of using ConnectivityManager#setNetworkPreference() but it has been deprecated in api 21. How can I set it to

How to find wifi and network data usage separately by particular application in android?

雨燕双飞 提交于 2019-12-03 03:14:14
recived = TrafficStats.getUidRxBytes(uid); send = TrafficStats.getUidTxBytes(uid); TrafficStats.getMobileRxBytes(); TrafficStats.getMobileTxBytes(); TrafficStats.getTotalRxBytes(); TrafficStats.getTotalTxBytes(); i have application id and i can get that application data usage but i cant get information in more detailed like data usage using wifi and network. i want to find both separately for all installed application in device. how can i find that.? i have already tried many things but didn't get any solution for that. artemiygrn I think you should use alternative way, get traffic by UID, for

Cannot make a static reference to the non-static method getSystemService(String) from the type

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-03 02:43:24
I have this function which network connection public boolean isNetworkConnected() { ConnectivityManager conManager = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo netInfo = conManager.getActiveNetworkInfo(); if (netInfo == null) { // There are no active networks. return false; } else { return true; } } But when i a trying to make it static so that i can use it in every activity it is throwing: Cannot make a static reference to the non-static method getSystemService(String) from the type I don't want to create the object of the class every time . Add the non

Android API-23: InetAddressUtils replacement

梦想的初衷 提交于 2019-12-03 01:34:48
Switching to Android Marshmallow API, I was using org.apache.http.conn.util.InetAddressUtils for InetAddressUtils.isIPv4Address(ipAddress) in a code to list all IPs from a device. As part of the API-23 changes , the InetAddressUtils class is now gone. How can I replace the below code now? public static String ipAddress() { try { for (final Enumeration<NetworkInterface> enumerationNetworkInterface = NetworkInterface.getNetworkInterfaces(); enumerationNetworkInterface.hasMoreElements();) { final NetworkInterface networkInterface = enumerationNetworkInterface.nextElement(); for (Enumeration

Capture network traffic programmatically (no root)

女生的网名这么多〃 提交于 2019-12-03 00:11:25
I'm trying to find resources or library which could permit me to capture the traffic of all the network packets of a device programmatically either it be from wifi or mobile network. I believe there no need to be root to be in this promiscuous mode as shark for root would request because there is this app on the play store which can capture all network traffic (even decrypt SSL with MITM) without needing to be root. I simply cannot figure out how to do the same. My question is: How did this app achieve this capture? What API did they use? Thank you for your help. The de-facto appraoch to

How do I fix 'android.os.NetworkOnMainThreadException'?

一世执手 提交于 2019-12-02 20:41:37
问题 I got an error while running my Android project for RssReader. Code: URL url = new URL(urlToRssFeed); SAXParserFactory factory = SAXParserFactory.newInstance(); SAXParser parser = factory.newSAXParser(); XMLReader xmlreader = parser.getXMLReader(); RssHandler theRSSHandler = new RssHandler(); xmlreader.setContentHandler(theRSSHandler); InputSource is = new InputSource(url.openStream()); xmlreader.parse(is); return theRSSHandler.getFeed(); And it shows the below error: android.os

Send data through wifi (no internet) when mobile data on

感情迁移 提交于 2019-12-02 18:53:34
I'm developing and application that connects to a hardware device through wifi (generated by the device) and send data to it through a socket connection. The problem is that when mobile data (3G/4G) is activated android tries to send the data through it instead of sending it through the wifi generated by the device, because because the wifi has no internet connection. I was thinking of using ConnectivityManager#setNetworkPreference() but it has been deprecated in api 21. How can I set it to send data using the wifi generated by the device instead of the mobile data interface? hygorxaraujo

How do I fix 'android.os.NetworkOnMainThreadException'?

馋奶兔 提交于 2019-12-02 11:46:51
I got an error while running my Android project for RssReader. Code: URL url = new URL(urlToRssFeed); SAXParserFactory factory = SAXParserFactory.newInstance(); SAXParser parser = factory.newSAXParser(); XMLReader xmlreader = parser.getXMLReader(); RssHandler theRSSHandler = new RssHandler(); xmlreader.setContentHandler(theRSSHandler); InputSource is = new InputSource(url.openStream()); xmlreader.parse(is); return theRSSHandler.getFeed(); And it shows the below error: android.os.NetworkOnMainThreadException How can I fix this issue? Michael Spector This exception is thrown when an application

Usage of consumeContent() of HttpEntity

夙愿已清 提交于 2019-12-02 09:23:31
问题 What is the purpose of consumeContent() of class or org.apache.http.HttpEntity in Android? When should one use it ane can it have side effects? I'm trying to fix a bug in an app which makes requests to a server using HttpClient and sometimes if one particular request fails it will subsequently fail despite the fact that internet is OK. The app calls this method at the end of input stream read. 回答1: As @Sotirios suggested, HttpEntity.consumeContent() is deprecated so please use EntityUtils

Android Retrofit POST ArrayList

删除回忆录丶 提交于 2019-12-02 04:57:55
问题 Trying to send List<String> to server and have Bad Request Error. public interface PostReviewApi { @FormUrlEncoded @POST("/") void addReview(@Field("review[place_id]") int placeId, @Field("review[content]") String review, @Field("review[rating]") float rating, @Field("review[tag_list]") List<String> tagsList, Callback<ReviewEntity> callback); } ... postApi.addReview(mRestaurantId, reviewText, (float) mRating, tagsList, new Callback<ReviewEntity>() { @Override public void success(ReviewEntity