Unable to connect with local server via android device - android

installed XAMPP server, created database and successfully accessed it from chrome browser as well as from android emulator. However whenever i try to run application from my Samsung device, its refusing to connect my IP address.
My IP address is not registered in DNS.
I tried:
1) accessing from url- 127.0.0.1 and localhost
2) modified httpd.conf and httpd-xampp.conf file- changed to Require all granted permission
3) uninstalled my Antivirus
4) changed firewall and proxy setting
5) Created new Inbound Rule in firewall advance security
6) re typed INTERNET permission
7) wrote httpPost.setHeader("Accept", "application/json"); in code
Still Im getting following error:
W/IInputConnectionWrapper(22232): getSelectedText on inactive InputConnection
W/IInputConnectionWrapper(22232): setComposingText on inactive InputConnection
W/IInputConnectionWrapper(22232): getSelectedText on inactive InputConnection
W/IInputConnectionWrapper(22232): setComposingText on inactive InputConnection
D/request!(22232): starting
W/System.err(22232): org.apache.http.conn.HttpHostConnectException: Connection to
http://192.XXX.X.XXX refused
W/System.err(22232): at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:183)
W/System.err(22232): at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
W/System.err(22232): at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
W/System.err(22232): at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)
W/System.err(22232): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
W/System.err(22232): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
W/System.err(22232): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
W/System.err(22232): at com.example.mysqltest.JSONParser.makeHttpRequest(JSONParser.java:111)
W/System.err(22232): at com.example.mysqltest.Login$AttemptLogin.doInBackground(Login.java:121)
W/System.err(22232): at com.example.mysqltest.Login$AttemptLogin.doInBackground(Login.java:1)
W/System.err(22232): at android.os.AsyncTask$2.call(AsyncTask.java:287)
W/System.err(22232): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
W/System.err(22232): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
W/System.err(22232): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
W/System.err(22232): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
W/System.err(22232): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
W/System.err(22232): at java.lang.Thread.run(Thread.java:856)
W/System.err(22232): Caused by: java.net.ConnectException: failed to connect to /192.168.0.114 (port 80): connect failed: ETIMEDOUT (Connection timed out)
W/System.err(22232): at libcore.io.IoBridge.connect(IoBridge.java:114)
W/System.err(22232): at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:192)
W/System.err(22232): at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:460)
W/System.err(22232): at java.net.Socket.connect(Socket.java:832)
W/System.err(22232): at `enter code here`org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:119)
W/System.err(22232): at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:144)
W/System.err(22232): ... 16 more
W/System.err(22232): Caused by: libcore.io.ErrnoException: connect failed: ETIMEDOUT (Connection timed out)
W/System.err(22232): at libcore.io.Posix.connect(Native Method)
W/System.err(22232): at libcore.io.BlockGuardOs.connect(BlockGuardOs.java:85)
W/System.err(22232): at libcore.io.IoBridge.connectErrno(IoBridge.java:127)
W/System.err(22232): at libcore.io.IoBridge.connect(IoBridge.java:112)
W/System.err(22232): ... 21 more
E/Buffer Error(22232): Error converting result java.lang.NullPointerException
E/JSON Parser(22232): Error parsing data org.json.JSONException: End of input at character 0 of
W/dalvikvm(22232): threadid=12: thread exiting with uncaught exception (group=0x41180438)
E/AndroidRuntime(22232): FATAL EXCEPTION: AsyncTask #1
E/AndroidRuntime(22232): java.lang.RuntimeException: An error occured while executing doInBackground()
E/AndroidRuntime(22232): at android.os.AsyncTask$3.done(AsyncTask.java:299)
E/AndroidRuntime(22232): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
E/AndroidRuntime(22232): at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
E/AndroidRuntime(22232): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
E/AndroidRuntime(22232): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
E/AndroidRuntime(22232): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
E/AndroidRuntime(22232): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
E/AndroidRuntime(22232): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
E/AndroidRuntime(22232): at java.lang.Thread.run(Thread.java:856)
E/AndroidRuntime(22232): Caused by: java.lang.NullPointerException
E/AndroidRuntime(22232): at com.example.mysqltest.Login$AttemptLogin.doInBackground(Login.java:125)
E/AndroidRuntime(22232): at com.example.mysqltest.Login$AttemptLogin.doInBackground(Login.java:1)
E/AndroidRuntime(22232): at android.os.AsyncTask$2.call(AsyncTask.java:287)
E/AndroidRuntime(22232): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
E/AndroidRuntime(22232): ... 5 more
I/Choreographer(22232): Skipped 1143 frames! The application may be doing too much work on its main thread.
E/WindowManager(22232): Activity com.example.mysqltest.Login has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView#41bea8a8 that was originally added here
E/WindowManager(22232): android.view.WindowLeaked: Activity com.example.mysqltest.Login has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView#41bea8a8 that was originally added here
E/WindowManager(22232): at android.view.ViewRootImpl.<init>(ViewRootImpl.java:419)
E/WindowManager(22232): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:322)
E/WindowManager(22232): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:234)
E/WindowManager(22232): at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:153)
E/WindowManager(22232): at android.view.Window$LocalWindowManager.addView(Window.java:557)
E/WindowManager(22232): at android.app.Dialog.show(Dialog.java:277)
E/WindowManager(22232): at com.example.mysqltest.Login$AttemptLogin.onPreExecute(Login.java:103)
E/WindowManager(22232): at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:586)
E/WindowManager(22232): at android.os.AsyncTask.execute(AsyncTask.java:534)
E/WindowManager(22232): at com.example.mysqltest.Login.onClick(Login.java:77)
E/WindowManager(22232): at android.view.View.performClick(View.java:4191)
E/WindowManager(22232): at android.view.View$PerformClick.run(View.java:17229)
E/WindowManager(22232): at android.os.Handler.handleCallback(Handler.java:615)
E/WindowManager(22232): at android.os.Handler.dispatchMessage(Handler.java:92)
E/WindowManager(22232): at android.os.Looper.loop(Looper.java:137)
E/WindowManager(22232): at android.app.ActivityThread.main(ActivityThread.java:4960)
E/WindowManager(22232): at java.lang.reflect.Method.invokeNative(Native Method)
E/WindowManager(22232): at java.lang.reflect.Method.invoke(Method.java:511)
E/WindowManager(22232): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
E/WindowManager(22232): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
E/WindowManager(22232): at dalvik.system.NativeStart.main(Native Method)"

Please try to check your local IP address of your PC. Connect the phone to the same network (WIFI). Then use the following address/port to connect to your PC.
In Android:
URL: your_pc_local_ip
PORT: 80 (but I think it is not mandatory)
I use in this way and it is working properly for me.

Related

Admob ads v11.6.0 with targetSdk=25 produce TimeoutException

When I use targetSdk=25, this error is written to logcat:
Error waiting for future.
java.util.concurrent.ExecutionException: java.util.concurrent.TimeoutException
at com.google.android.gms.ads.internal.util.future.ac.get(:com.google.android.gms#11951036:12)
at com.google.android.gms.ads.internal.util.future.g.a(:com.google.android.gms#11951036:12)
at com.google.android.gms.ads.internal.request.service.c.a(:com.google.android.gms#11951036:51)
at com.google.android.gms.ads.internal.request.service.c.a(:com.google.android.gms#11951036:182)
at com.google.android.gms.ads.internal.request.service.f.run(:com.google.android.gms#11951036:2)
at com.google.android.gms.ads.internal.util.x.call(:com.google.android.gms#11951036:2)
at com.google.android.gms.ads.internal.util.y.run(:com.google.android.gms#11951036:1)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:390)
at java.util.concurrent.FutureTask.run(FutureTask.java:234)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
at java.lang.Thread.run(Thread.java:841)
Caused by: java.util.concurrent.TimeoutException
at com.google.android.gms.ads.internal.util.future.k.run(Unknown Source)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:390)
at java.util.concurrent.FutureTask.run(FutureTask.java:234)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:153)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:267)
... 3 more
With targetSdk=26 no error is written to Logcat.
Is it ok to use Admob v11.6.0 if targetSdk=25?

Facebook Login example runtime exception

My facebook login application fails with the following runtime error:
07-31 12:47:10.195 1309-1316/com.android.quicksearchbox E/jdwp﹕ Failed writing handshake bytes: Broken pipe (-1 of 14)
07-31 12:47:11.004 1341-1358/com.example.apurva.myapplication E/ActivityThread﹕ Failed to find provider info for com.facebook.katana.provider.AttributionIdProvider
07-31 12:47:11.094 1341-1360/com.example.apurva.myapplication E/AndroidRuntime﹕ FATAL EXCEPTION: AsyncTask #2
java.lang.RuntimeException: An error occured while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:278)
at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
at java.util.concurrent.FutureTask.run(FutureTask.java:137)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:208)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
at java.lang.Thread.run(Thread.java:856)
Caused by: java.lang.NullPointerException
at java.util.concurrent.ConcurrentHashMap.containsKey(ConcurrentHashMap.java:781)
at com.facebook.internal.Utility.queryAppSettings(Utility.java:802)
at com.facebook.login.widget.LoginButton$1.doInBackground(LoginButton.java:502)
at com.facebook.login.widget.LoginButton$1.doInBackground(LoginButton.java:499)
at android.os.AsyncTask$2.call(AsyncTask.java:264)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
            at java.util.concurrent.FutureTask.run(FutureTask.java:137)
            at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:208)
            at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
            at java.lang.Thread.run(Thread.java:856)
A few pointers on what I have done till now:
1)Followed all the requirements in Facebook's Getting Started post.
2)Added the meta-data to the XML.
3)Added the key-hash to facebook
If you see any particular files that might be causing the problem and want to see it before answering, do let me know.

What Can I do to manage cells that says they have Internet but that can't reach any site

I am experimenting errors in my app, when cell is telling that it is connected to internet, but when you try to connect google play or browser, you can see there is no internet.
It can happen when user is at the limit of Wifi Range, or when there is a very bad 3g signal, or when the device has not so good hardware ( I have a lot of problems with Samsung Advance with Android 4.1.2)
The consequence is I have a lot of errors like:
ECONNRESET (Connection reset by peer)
or
java.net.UnknownHostException: Unable to resolve host "mysite.com": No address associated with hostname
at java.net.InetAddress.lookupHostByName(InetAddress.java:424)
at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236)
at java.net.InetAddress.getAllByName(InetAddress.java:214)
at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:137)
at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
at com.myapp.action.CapturaDAO.uploadCapturas(CapturaDAO.java:70)
at com.myapp.action.SyncData.doInBackground(SyncData.java:148)
at com.myapp.action.SyncData.doInBackground(SyncData.java:1)
at android.os.AsyncTask$2.call(AsyncTask.java:287)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
at java.util.concurrent.FutureTask.run(FutureTask.java:137)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
at java.lang.Thread.run(Thread.java:856)
Caused by: libcore.io.GaiException: getaddrinfo failed: EAI_NODATA (No address associated with hostname)
at libcore.io.Posix.getaddrinfo(Posix.java)
at libcore.io.ForwardingOs.getaddrinfo(ForwardingOs.java:55)
at java.net.InetAddress.lookupHostByName(InetAddress.java:405)
at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236)
at java.net.InetAddress.getAllByName(InetAddress.java:214)
at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:137)
at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
at com.myapp.action.CapturaDAO.uploadCapturas(CapturaDAO.java:70)
at com.myapp.action.SyncData.doInBackground(SyncData.java:148)
at com.myapp.action.SyncData.doInBackground(SyncData.java:1)
at android.os.AsyncTask$2.call(AsyncTask.java:287)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
at java.util.concurrent.FutureTask.run(FutureTask.java:137)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
at java.lang.Thread.run(Thread.java:856)
Caused by: libcore.io.ErrnoException: getaddrinfo failed: ENETUNREACH (Network is unreachable)
at libcore.io.Posix.getaddrinfo(Posix.java)
at libcore.io.ForwardingOs.getaddrinfo(ForwardingOs.java:55)
at java.net.InetAddress.lookupHostByName(InetAddress.java:405)
at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236)
at java.net.InetAddress.getAllByName(InetAddress.java:214)
at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:137)
at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
at com.myapp.action.CapturaDAO.uploadCapturas(CapturaDAO.java:70)
at com.myapp.action.SyncData.doInBackground(SyncData.java:148)
at com.myapp.action.SyncData.doInBackground(SyncData.java:1)
at android.os.AsyncTask$2.call(AsyncTask.java:287)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
at java.util.concurrent.FutureTask.run(FutureTask.java:137)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
at java.lang.Thread.run(Thread.java:856)
When loading, it lasts a lot.
My first question is: Is it consuming high battery while trying to connect host???
My real question: is it posible to manage this case? Is there a way to detect there is no internet while system says there is?
EDIT:
I'm checking the internet connection with that method :
public static boolean isOnline(Context ctx) {
ConnectivityManager cm = (ConnectivityManager) ctx
.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo netInfo = cm.getActiveNetworkInfo();
if (netInfo != null && netInfo.isConnectedOrConnecting()) {
return true;
}
return false;
}
My first question is: Is it consuming high battery while trying to connect host???
Battery consumption should be normal as it is using the wi-fi or mobile radio.
My real question: is it possible to manage this case? Is there a way to detect there is no internet while system says there is?
You can add a timeout of say 30 sec with your request using URLConnection's setConnectionTimeput() method. In case of connection time out you can notify the user about weak connection.

Http post request inside a GPS Listener...initiated by a Service

I'm doing an app in which a Service initiates a GPSListener which gets location updates in a regular interval of time.Upto this part its woking fine,and Im getting updates correctly.
I need to update this lat,long values to a server database,for which I use a http post request to a php script;which individually works fien.But when its called inside the LocationListener,Im getting the following error stacktrace.
How can I overcome this situation and make the post request?
> android.os.NetworkOnMainThreadException
at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1117)
at java.net.InetAddress.lookupHostByName(InetAddress.java:385)
at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236)
at java.net.InetAddress.getAllByName(InetAddress.java:214)
at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:137)
at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
at com.childtrack.service.SimpleService$mylocationlistener.postData(SimpleService.java:165)
at com.childtrack.service.SimpleService$mylocationlistener.onLocationChanged(SimpleService.java:101)
at android.location.LocationManager$ListenerTransport._handleMessage(LocationManager.java:237)
at android.location.LocationManager$ListenerTransport.access$000(LocationManager.java:170)
at android.location.LocationManager$ListenerTransport$1.handleMessage(LocationManager.java:186)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4899)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:558)
at dalvik.system.NativeStart.main(Native Method)
W/System.err(5560): android.os.NetworkOnMainThreadException
at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1117)
at java.net.InetAddress.lookupHostByName(InetAddress.java:385)
at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236)
at java.net.InetAddress.getAllByName(InetAddress.java:214)
at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:137)
at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
at com.childtrack.service.SimpleService$mylocationlistener.postData(SimpleService.java:165)
at com.childtrack.service.SimpleService$mylocationlistener.onLocationChanged(SimpleService.java:101)
at android.location.LocationManager$ListenerTransport._handleMessage(LocationManager.java:237)
at android.location.LocationManager$ListenerTransport.access$000(LocationManager.java:170)
at android.location.LocationManager$ListenerTransport$1.handleMessage(LocationManager.java:186)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4899)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:558)
at dalvik.system.NativeStart.main(Native Method)
you are doing network operation on main(UI) thread. do use asyntask for network operation.
android does not allow to perform network operation on main thread. because it may freezes the UI.
whenever this exception occur android.os.NetworkOnMainThreadException its mean you have done something network operation on UI.
Even though Service is intended for background processing they run in the main thread .
A short quote from the documentation:
Caution: A services runs in the same process as the application in which
it is declared and in the main thread of that application, by default. So,
if your service performs intensive or blocking operations while the user
interacts with an activity from the same application, the service will
slow down activity performance. To avoid impacting application performance,
you should start a new thread inside the service.

Unable to download an image in android

I need to download twitter profile picture of mine and show it in an imageview on click of a button. Here is my code to download the profile picture of desired user.
public static InputStream getTwitterProfilePictureOfUser(String twitterId){
try {
return new DefaultHttpClient().execute(new HttpGet("http://api.twitter.com/1/users/profile_image?user_id="+twitterId+"&size=bigger")).getEntity().getContent();
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
Getting the following exceptions. Where i'am going wrong ?
javax.net.ssl.SSLException: Not trusted server certificate
at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:371)
at org.apache.http.conn.ssl.AbstractVerifier.verify(AbstractVerifier.java:92)
at org.apache.http.conn.ssl.SSLSocketFactory.createSocket(SSLSocketFactory.java:381)
at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:174)
at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:348)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
at com.tarams.android.giveblood.service.ServiceStub.getTwitterProfilePictureOfUser(ServiceStub.java:207)
at com.tarams.android.giveblood.activities.ProfileActivity.onCreate(ProfileActivity.java:128)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2633)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2685)
at android.app.ActivityThread.access$2300(ActivityThread.java:126)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2038)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4633)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.security.cert.CertificateException: java.security.cert.CertPathValidatorException: TrustAnchor for CertPath not found.
at org.apache.harmony.xnet.provider.jsse.TrustManagerImpl.checkServerTrusted(TrustManagerImpl.java:168)
at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:366)
... 24 more
Caused by: java.security.cert.CertPathValidatorException: TrustAnchor for CertPath not found.
at org.bouncycastle.jce.provider.PKIXCertPathValidatorSpi.engineValidate(PKIXCertPathValidatorSpi.java:149)
at java.security.cert.CertPathValidator.validate(CertPathValidator.java:202)
at org.apache.harmony.xnet.provider.jsse.TrustManagerImpl.checkServerTrusted(TrustManagerImpl.java:164)
You are attempting to connect to an HTTPS URL via and the SSL certificate provided by the site is not trusted by the devise you are running the code on. I suggest you read this question on setting up trust in the Apache HTTP Client

Categories

Resources