android-networking

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

笑着哭i 提交于 2019-11-26 05:40:23
问题 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

Intent action for network events in android sdk

[亡魂溺海] 提交于 2019-11-26 03:09:54
问题 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

How do I pass a multi part body parameter for rxjava2 androidnetworking POST request?

[亡魂溺海] 提交于 2019-11-26 02:39:14
问题 I have been struggling to figure out how to pass a file via the body of a post request. I tried a couple of things online, but nothing quite matches my use case. Here\'s the postman screen shot for my server code: So, as you can see \"photo\" is in the body section as a key (file) and the value is an image file. This is a post request on the whole and returns no response when the query is successful.(just shows the status as created, as you can see from the screenshot)[also note:it requires

Android check internet connection [duplicate]

大憨熊 提交于 2019-11-26 01:19:58
问题 This question already has answers here : How to check internet access on Android? InetAddress never times out (51 answers) Closed 3 years ago . I want to create an app that uses the internet and I\'m trying to create a function that checks if a connection is available and if it isn\'t, go to an activity that has a retry button and an explanation. Attached is my code so far, but I\'m getting the error Syntax error, insert \"}\" to complete MethodBody. Now I have been placing these in trying to

Network listener Android

只愿长相守 提交于 2019-11-26 00:52:21
问题 I want to check when the network of phone in Android goes off. Can I capture that event? I am not getting the proper API or any example which would explain the same. If anyone had done or any example links would be really helpful. 回答1: New java class: public class ConnectionChangeReceiver extends BroadcastReceiver { @Override public void onReceive( Context context, Intent intent ) { ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService( Context.CONNECTIVITY

Broadcast receiver for checking internet connection in android app

我是研究僧i 提交于 2019-11-25 22:20:56
问题 I am developing an android broadcast receiver for checking internet connection. The problem is that my broadcast receiver is being called two times. I want it to get called only when the network is available. If it is unavailable, I don\'t want notified. This is the broadcast receiver public class NetworkChangeReceiver extends BroadcastReceiver { @Override public void onReceive(final Context context, final Intent intent) { final ConnectivityManager connMgr = (ConnectivityManager) context

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

孤者浪人 提交于 2019-11-25 22:05:39
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 3 years ago . Two-part question from an iOS developer learning Android, working on an Android project that will make a variety of requests from JSON to image to streaming download of audio and video: On iOS I have used the AFNetworking project extensively. Is there an equivalent library for Android? I\'ve read up on OkHTTP

Network listener Android

时间秒杀一切 提交于 2019-11-25 20:48:39
I want to check when the network of phone in Android goes off. Can I capture that event? I am not getting the proper API or any example which would explain the same. If anyone had done or any example links would be really helpful. New java class: public class ConnectionChangeReceiver extends BroadcastReceiver { @Override public void onReceive( Context context, Intent intent ) { ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService( Context.CONNECTIVITY_SERVICE ); NetworkInfo activeNetInfo = connectivityManager.getActiveNetworkInfo(); NetworkInfo mobNetInfo =