SSLHandshakeException: Certificate Exception using HttpURLConnetion with Android 4.2.2 - android

I am struggling with a strange issue, while using HttpURLConnection for webservice api call in Android. I am getting below exception ONLY with Android version 4.2.2. It is working fine in Android 4.0.3, 4.3 and 4.4 and above.
I am using below code for service api call.
HttpURLConnection mConn = (HttpURLConnection)mUrl.openConnection();
mConn.addRequestProperty("Connection", "close");
mConn.setConnectTimeout(CONNECTION_TIMEOUT);
mConn.setReadTimeout(SOCKET_TIMEOUT);
mConn.setUseCaches(true);
mConn.setRequestMethod("POST");
String param = Utils.appendQueryParams(null,this.stringparams);
mConn.setDoInput(true);
mConn.setDoOutput(true);
mConn.setFixedLengthStreamingMode(param.getBytes().length);
mConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
mConn.setRequestProperty("Accept", "application/json");
mConn.connect();
PrintWriter out = new PrintWriter(mConn.getOutputStream());
out.print(param);
out.close();
Here is the Exception (ONLY in Android SDK version 4.2.2)
08-18 11:43:22.663 26427-26485/com.abc.xyz W/System.err﹕ javax.net.ssl.SSLHandshakeException: com.android.org.bouncycastle.jce.exception.ExtCertPathValidatorException: IssuerName(CN=Go Daddy Root Certificate Authority - G2, O="GoDaddy.com, Inc.", L=Scottsdale, ST=Arizona, C=US) does not match SubjectName(CN=Go Daddy Root Certificate Authority - G2, OU=https://certs.godaddy.com/repository/, O="GoDaddy.com, Inc.", L=Scottsdale, ST=Arizona, C=US) of signing certificate.
08-18 11:43:22.833 26427-26485/com.abc.xyz W/System.err﹕ at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:381)
08-18 11:43:22.833 26427-26485/com.abc.xyz W/System.err﹕ at libcore.net.http.HttpConnection.setupSecureSocket(HttpConnection.java:209)
08-18 11:43:22.833 26427-26485/com.abc.xyz W/System.err﹕ at libcore.net.http.HttpsURLConnectionImpl$HttpsEngine.makeSslConnection(HttpsURLConnectionImpl.java:478)
08-18 11:43:22.833 26427-26485/com.abc.xyz W/System.err﹕ at libcore.net.http.HttpsURLConnectionImpl$HttpsEngine.connect(HttpsURLConnectionImpl.java:433)
08-18 11:43:22.833 26427-26485/com.abc.xyz W/System.err﹕ at libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:290)
08-18 11:43:22.833 26427-26485/com.abc.xyz W/System.err﹕ at libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:240)
08-18 11:43:22.833 26427-26485/com.abc.xyz W/System.err﹕ at libcore.net.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:81)
08-18 11:43:22.833 26427-26485/com.abc.xyz W/System.err﹕ at libcore.net.http.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java:165)
08-18 11:43:22.833 26427-26485/com.abc.xyz W/System.err﹕ at com.halomem.android.utils.ServiceCall.executeRequest(ServiceCall.java:86)
08-18 11:43:22.833 26427-26485/com.abc.xyz W/System.err﹕ at com.halomem.android.impl.Session$1.run(Session.java:161)
08-18 11:43:22.833 26427-26485/com.abc.xyz W/System.err﹕ Caused by: java.security.cert.CertificateException: com.android.org.bouncycastle.jce.exception.ExtCertPathValidatorException: IssuerName(CN=Go Daddy Root Certificate Authority - G2, O="GoDaddy.com, Inc.", L=Scottsdale, ST=Arizona, C=US) does not match SubjectName(CN=Go Daddy Root Certificate Authority - G2, OU=https://certs.godaddy.com/repository/, O="GoDaddy.com, Inc.", L=Scottsdale, ST=Arizona, C=US) of signing certificate.
08-18 11:43:22.833 26427-26485/com.abc.xyz W/System.err﹕ at org.apache.harmony.xnet.provider.jsse.TrustManagerImpl.checkTrusted(TrustManagerImpl.java:296)
08-18 11:43:22.833 26427-26485/com.abc.xyz W/System.err﹕ at org.apache.harmony.xnet.provider.jsse.TrustManagerImpl.checkServerTrusted(TrustManagerImpl.java:197)
08-18 11:43:22.833 26427-26485/com.abc.xyz W/System.err﹕ at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.verifyCertificateChain(OpenSSLSocketImpl.java:597)
08-18 11:43:22.833 26427-26485/com.abc.xyz W/System.err﹕ at org.apache.harmony.xnet.provider.jsse.NativeCrypto.SSL_do_handshake(Native Method)
08-18 11:43:22.833 26427-26485/com.abc.xyz W/System.err﹕ at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:378)
08-18 11:43:22.833 26427-26485/com.abc.xyz W/System.err﹕ ... 9 more
08-18 11:43:22.833 26427-26485/com.abc.xyz W/System.err﹕ Caused by: com.android.org.bouncycastle.jce.exception.ExtCertPathValidatorException: IssuerName(CN=Go Daddy Root Certificate Authority - G2, O="GoDaddy.com, Inc.", L=Scottsdale, ST=Arizona, C=US) does not match SubjectName(CN=Go Daddy Root Certificate Authority - G2, OU=https://certs.godaddy.com/repository/, O="GoDaddy.com, Inc.", L=Scottsdale, ST=Arizona, C=US) of signing certificate.
08-18 11:43:22.843 26427-26485/com.abc.xyz W/System.err﹕ at com.android.org.bouncycastle.jce.provider.RFC3280CertPathUtilities.processCertA(RFC3280CertPathUtilities.java:1525)
08-18 11:43:22.843 26427-26485/com.abc.xyz W/System.err﹕ at com.android.org.bouncycastle.jce.provider.PKIXCertPathValidatorSpi.engineValidate(PKIXCertPathValidatorSpi.java:305)
08-18 11:43:22.843 26427-26485/com.abc.xyz W/System.err﹕ at com.sec.android.security.pkix.SecCertPathValidatorSpi.engineValidate(SecCertPathValidatorSpi.java:99)
08-18 11:43:22.843 26427-26485/com.abc.xyz W/System.err﹕ at java.security.cert.CertPathValidator.validate(CertPathValidator.java:190)
08-18 11:43:22.843 26427-26485/com.abc.xyz W/System.err﹕ at org.apache.harmony.xnet.provider.jsse.TrustManagerImpl.checkTrusted(TrustManagerImpl.java:283)
08-18 11:43:22.843 26427-26485/com.abc.xyz W/System.err﹕ ... 13 more
Please suggest in this regard.
Thanks
Himanshu.

Important note
Check your device time is correct or not ?

Seems like authority of certificate is not trusted on your device. Checkout this post: Could not validate certificate signature?

Related

Picasso is not loading images from the external storage

Using Picasso (version 2.5.2) in my android project and trying to load all the images stored in the device in a grid view. Picasso is successfully loading all the images stored in the internal storage but not loading those from the external storage. Also, not getting any errors in the log.
I also checked if the file exists and loaded that successfully in a view using Glide library.
Sample external file path:
/storage/0403-0201/DCIM/Camera/IMG_20180309_120329.jpg
#CommonsWare, Thanks a lot! I attached Picasso.Listener and got the following stack trace-
W/System.err﹕ java.io.IOException: Cannot reset
W/System.err﹕ at com.squareup.picasso.MarkableInputStream.reset(MarkableInputStream.java:99)
W/System.err﹕ at com.squareup.picasso.BitmapHunter.decodeStream(BitmapHunter.java:140)
W/System.err﹕ at com.squareup.picasso.BitmapHunter.hunt(BitmapHunter.java:217)
W/System.err﹕ at com.squareup.picasso.BitmapHunter.run(BitmapHunter.java:159)
W/System.err﹕ at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422)
W/System.err﹕ at java.util.concurrent.FutureTask.run(FutureTask.java:237)
W/System.err﹕ at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
W/System.err﹕ at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
W/System.err﹕ at java.lang.Thread.run(Thread.java:841)
W/System.err﹕ at com.squareup.picasso.Utils$PicassoThread.run(Utils.java:394)
W/System.err﹕ java.io.IOException: Cannot reset
W/System.err﹕ at com.squareup.picasso.MarkableInputStream.reset(MarkableInputStream.java:99)
W/System.err﹕ at com.squareup.picasso.BitmapHunter.decodeStream(BitmapHunter.java:140)
W/System.err﹕ at com.squareup.picasso.BitmapHunter.hunt(BitmapHunter.java:217)
W/System.err﹕ at com.squareup.picasso.BitmapHunter.run(BitmapHunter.java:159)
W/System.err﹕ at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422)
W/System.err﹕ at java.util.concurrent.FutureTask.run(FutureTask.java:237)
W/System.err﹕ at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
W/System.err﹕ at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
W/System.err﹕ at java.lang.Thread.run(Thread.java:841)
W/System.err﹕ at com.squareup.picasso.Utils$PicassoThread.run(Utils.java:394)
I explored this error and found that Picasso 2.5.2 does not display big images and same has been filed as a bug on Picasso github page.
https://github.com/square/picasso/issues/907
Solution: Picasso 2.5.x is having the bug but version 2.4.0 is working fine.

AWS API Gateway REST DELETE method call from android app working fine in emulator but not working from device?

I am calling AWS API Gateway REST service from my android app through AsyncTask. All method working fine both in emulator and device. But when I call delete then in emulator working fine but from device it is giving an error that
java.lang.reflect.UndeclaredThrowableException
09-28 15:32:03.133 12335-12824/com.example.nmsapp W/System.err﹕ at $Proxy1.userDelete(Native Method)
09-28 15:32:03.133 12335-12824/com.example.nmsapp W/System.err﹕ at com.example.nmsapp.CustomUserAdapter$DeleteUsers.doInBackground(CustomUserAdapter.java:130)
09-28 15:32:03.133 12335-12824/com.example.nmsapp W/System.err﹕ at com.example.nmsapp.CustomUserAdapter$DeleteUsers.doInBackground(CustomUserAdapter.java:107)
09-28 15:32:03.133 12335-12824/com.example.nmsapp W/System.err﹕ at android.os.AsyncTask$2.call(AsyncTask.java:288)
09-28 15:32:03.133 12335-12824/com.example.nmsapp W/System.err﹕ at java.util.concurrent.FutureTask.run(FutureTask.java:237)
09-28 15:32:03.133 12335-12824/com.example.nmsapp W/System.err﹕ at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
09-28 15:32:03.133 12335-12824/com.example.nmsapp W/System.err﹕ at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
09-28 15:32:03.133 12335-12824/com.example.nmsapp W/System.err﹕ at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
09-28 15:32:03.133 12335-12824/com.example.nmsapp W/System.err﹕ at java.lang.Thread.run(Thread.java:841)
09-28 15:32:03.133 12335-12824/com.example.nmsapp W/System.err﹕ Caused by: java.net.ProtocolException: DELETE does not support writing
09-28 15:32:03.133 12335-12824/com.example.nmsapp W/System.err﹕ at com.android.okhttp.internal.http.HttpURLConnectionImpl.initHttpEngine(HttpURLConnectionImpl.java:258)
09-28 15:32:03.133 12335-12824/com.example.nmsapp W/System.err﹕ at com.android.okhttp.internal.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:86)
09-28 15:32:03.133 12335-12824/com.example.nmsapp W/System.err﹕ at com.android.okhttp.internal.http.HttpURLConnectionImpl.getOutputStream(HttpURLConnectionImpl.java:197)
09-28 15:32:03.133 12335-12824/com.example.nmsapp W/System.err﹕ at com.android.okhttp.internal.http.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java:254)
09-28 15:32:03.133 12335-12824/com.example.nmsapp W/System.err﹕ at com.amazonaws.http.UrlHttpClient.writeContentToConnection(UrlHttpClient.java:128)
09-28 15:32:03.133 12335-12824/com.example.nmsapp W/System.err﹕ at com.amazonaws.http.UrlHttpClient.execute(UrlHttpClient.java:65)
09-28 15:32:03.133 12335-12824/com.example.nmsapp W/System.err﹕ at com.amazonaws.mobileconnectors.apigateway.ApiClientHandler.invoke(ApiClientHandler.java:91)
Android Menifest permission are:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
DELETE with body can lead to unexpected behavior. Per HTTP/1.1 RFC2616, this is neither allowed not disallowed. However, depending on which HTTP library you use, the behavior may vary. As for the generated API Gateway client, its uses HttpURLConnection as recommended by Android. Nevertheless, the implementation of HttpURLConnection is platform dependent. Priory to API level 19, it's close to Java's standard implementation by Sun, where ProtocolException will be thrown on DELETE with body. Since API level 19, Android switches to OkHttp which permits such behavior (see https://github.com/square/okhttp/issues/605). This should explain why it works on some place but not the other. In summary, I suggest you avoid defining an API which does DELETE with body.

Ion using HTTPS

I'm using Ion but when i try to use it with Https it gives me an exception.
Code:
Ion.with(getApplicationContext())
.load(mBaseUrl + "Token")
.setJsonObjectBody(json)
(...)
Exception:
09-24 11:53:00.211 17654-17940/com.gfi.connectelu W/System.err﹕ javax.net.ssl.SSLHandshakeException: Handshake failed
09-24 11:53:00.211 17654-17940/com.gfi.connectelu W/System.err﹕ at com.google.android.gms.org.conscrypt.OpenSSLEngineImpl.unwrap(SourceFile:421)
09-24 11:53:00.211 17654-17940/com.gfi.connectelu W/System.err﹕ at javax.net.ssl.SSLEngine.unwrap(SSLEngine.java:383)
09-24 11:53:00.211 17654-17940/com.gfi.connectelu W/System.err﹕ at com.koushikdutta.async.AsyncSSLSocketWrapper$4.onDataAvailable(AsyncSSLSocketWrapper.java:172)
09-24 11:53:00.211 17654-17940/com.gfi.connectelu W/System.err﹕ at com.koushikdutta.async.BufferedDataEmitter.onDataAvailable(BufferedDataEmitter.java:33)
09-24 11:53:00.211 17654-17940/com.gfi.connectelu W/System.err﹕ at com.koushikdutta.async.BufferedDataEmitter.onDataAvailable(BufferedDataEmitter.java:61)
09-24 11:53:00.211 17654-17940/com.gfi.connectelu W/System.err﹕ at com.koushikdutta.async.Util.emitAllData(Util.java:20)
09-24 11:53:00.211 17654-17940/com.gfi.connectelu W/System.err﹕ at com.koushikdutta.async.AsyncNetworkSocket.onReadable(AsyncNetworkSocket.java:175)
09-24 11:53:00.211 17654-17940/com.gfi.connectelu W/System.err﹕ at com.koushikdutta.async.AsyncServer.runLoop(AsyncServer.java:766)
09-24 11:53:00.211 17654-17940/com.gfi.connectelu W/System.err﹕ at com.koushikdutta.async.AsyncServer.run(AsyncServer.java:608)
09-24 11:53:00.211 17654-17940/com.gfi.connectelu W/System.err﹕ at com.koushikdutta.async.AsyncServer.access$700(AsyncServer.java:37)
09-24 11:53:00.211 17654-17940/com.gfi.connectelu W/System.err﹕ at com.koushikdutta.async.AsyncServer$13.run(AsyncServer.java:557)
09-24 11:53:00.211 17654-17940/com.gfi.connectelu W/System.err﹕ Caused by: java.security.cert.CertificateException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
09-24 11:53:00.211 17654-17940/com.gfi.connectelu W/System.err﹕ at com.android.org.conscrypt.TrustManagerImpl.checkTrusted(TrustManagerImpl.java:282)
09-24 11:53:00.211 17654-17940/com.gfi.connectelu W/System.err﹕ at com.android.org.conscrypt.TrustManagerImpl.checkServerTrusted(TrustManagerImpl.java:192)
09-24 11:53:00.211 17654-17940/com.gfi.connectelu W/System.err﹕ at com.google.android.gms.org.conscrypt.Platform.checkServerTrusted(SourceFile:158)
09-24 11:53:00.211 17654-17940/com.gfi.connectelu W/System.err﹕ at com.google.android.gms.org.conscrypt.OpenSSLEngineImpl.verifyCertificateChain(SourceFile:629)
09-24 11:53:00.211 17654-17940/com.gfi.connectelu W/System.err﹕ at com.google.android.gms.org.conscrypt.NativeCrypto.SSL_do_handshake_bio(Native Method)
09-24 11:53:00.211 17654-17940/com.gfi.connectelu W/System.err﹕ at com.google.android.gms.org.conscrypt.OpenSSLEngineImpl.unwrap(SourceFile:411)
09-24 11:53:00.211 17654-17940/com.gfi.connectelu W/System.err﹕ ... 10 more
09-24 11:53:00.211 17654-17940/com.gfi.connectelu W/System.err﹕ Caused by: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
There has been a recent reported issue about SSL Handshake on Ion:
Meanwhile, you could maybe take a look at Ion: add support for self signed certificates
You are talking to a server with a bad certificate. If it's a self signed certificate, you need to install that in your ion's http client.
java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.

File write permission error in Android

I am writing a file to SDCard and set <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> it works good upto 3.x but on 4.0 it gives the below error.
java.io.IOException: open failed: EACCES (Permission denied)
at java.io.File.createNewFile(File.java:940)
at com.gt.mLearning.app.VideoViewActivity.copyFile(VideoViewActivity.java:204)
at com.gt.mLearning.app.VideoViewActivity.access$3(VideoViewActivity.java:193)
at com.gt.mLearning.app.VideoViewActivity$Loader.doInBackground(VideoViewActivity.java:61)
at com.gt.mLearning.app.VideoViewActivity$Loader.doInBackground(VideoViewActivity.java:1)
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 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: open failed: EACCES (Permission denied)
at libcore.io.Posix.open(Native Method)
at libcore.io.BlockGuardOs.open(BlockGuardOs.java:110)
at java.io.File.createNewFile(File.java:933)
Any help or suggestion?
rohit
Just guessing but did you probably have your phone still connected to the computer? This error might happen if your sd card is still locked as a usb device.
Hope this helped,
Tobias
Latter on I discovered that the issue is device specific. I installed the File Manager app from Android market and it shows no write permission. It mean the Android OS implementation of that manufacturer do not provide write permission which is causing the issue.
Probably you have hard-coded the external storage directory and it works on particular devices.
Environment.getExternalStorageDirectory();
Posting your code will help much more than just the log.
You may check you've just updated your Android O/S, too. Some major change cause sdcard problem. For me, I update my Android O/S in SHV-E160K from 2.3.5 to 4.1.2 with Odin which is samsung firmware update application. And I faced problem.
My detailed error message is as follows :
02-14 11:00:43.057 22288-22288/? W/System.err﹕ java.io.IOException: open failed: EACCES (Permission denied)
02-14 11:00:43.057 22288-22288/? W/System.err﹕ at java.io.File.createNewFile(File.java:940)
02-14 11:00:43.057 22288-22288/? W/System.err﹕ at com.sec.android.util.IAPDeviceInfoEditor.activity.EditorActivity.createDeviceInfo(EditorActivity.java:222)
02-14 11:00:43.057 22288-22288/? W/System.err﹕ at com.sec.android.util.IAPDeviceInfoEditor.activity.EditorActivity.onClick(EditorActivity.java:121)
02-14 11:00:43.057 22288-22288/? W/System.err﹕ at java.lang.reflect.Method.invokeNative(Native Method)
02-14 11:00:43.057 22288-22288/? W/System.err﹕ at java.lang.reflect.Method.invoke(Method.java:511)
02-14 11:00:43.057 22288-22288/? W/System.err﹕ at android.view.View$1.onClick(View.java:3685)
02-14 11:00:43.057 22288-22288/? W/System.err﹕ at android.view.View.performClick(View.java:4192)
02-14 11:00:43.067 22288-22288/? W/System.err﹕ at android.view.View$PerformClick.run(View.java:17248)
02-14 11:00:43.067 22288-22288/? W/System.err﹕ at android.os.Handler.handleCallback(Handler.java:615)
02-14 11:00:43.067 172-485/? V/AudioHardwareMSM8660﹕ open driver
02-14 11:00:43.067 22288-22288/? W/System.err﹕ at android.os.Handler.dispatchMessage(Handler.java:92)
02-14 11:00:43.067 22288-22288/? W/System.err﹕ at android.os.Looper.loop(Looper.java:137)
02-14 11:00:43.067 22288-22288/? W/System.err﹕ at android.app.ActivityThread.main(ActivityThread.java:4950)
02-14 11:00:43.067 22288-22288/? W/System.err﹕ at java.lang.reflect.Method.invokeNative(Native Method)
02-14 11:00:43.067 22288-22288/? W/System.err﹕ at java.lang.reflect.Method.invoke(Method.java:511)
02-14 11:00:43.067 22288-22288/? W/System.err﹕ at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:997)
02-14 11:00:43.067 22288-22288/? W/System.err﹕ at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:764)
02-14 11:00:43.067 22288-22288/? W/System.err﹕ at dalvik.system.NativeStart.main(Native Method)
02-14 11:00:43.067 22288-22288/? W/System.err﹕ Caused by: libcore.io.ErrnoException: open failed: EACCES (Permission denied)
02-14 11:00:43.067 22288-22288/? W/System.err﹕ at libcore.io.Posix.open(Native Method)
02-14 11:00:43.067 22288-22288/? W/System.err﹕ at libcore.io.BlockGuardOs.open(BlockGuardOs.java:110)
02-14 11:00:43.067 22288-22288/? W/System.err﹕ at java.io.File.createNewFile(File.java:933)
02-14 11:00:43.067 22288-22288/? W/System.err﹕ ... 16 more
The reason is 4.1.2 couldn't recognize file system in 2.3.5. I solve this formatting sdcard storage. format doesn't mean delete your personal information such as address, memo or history. After format, it works like magic.
This may help you.
I faced the same issue when writing the file on sdcard. I have set all required permission to write the file but i used file object like below:
Wrong :
File myFile = new File(Environment.getExternalStorageDirectory().getAbsoluteFile()+fileName);
Correct:
File myFile = new File(Environment.getExternalStorageDirectory().getAbsoluteFile(), fileName);
That means the path was wrong.

Service not Available - Geocoder Android [duplicate]

This question already has answers here:
Why is Android Geocoder throwing a "Service not Available" exception?
(6 answers)
Closed 9 years ago.
I have a little problem with the geocoder to get latitude and lontitude from an address :
This is my code:
for (Garage g : XMLGarage) {
List<Address> address;
address = coder.getFromLocationName(
g.getAddress(), 5);
if (address != null) {
Address location = address.get(0);
g.setLatitude(location.getLatitude());
g.setLongitude(location.getLongitude());
...
The error is :
08-18 14:28:56.026: WARN/System.err(359): java.io.IOException: Service not Available
08-18 14:28:56.026: WARN/System.err(359): at
android.location.Geocoder.getFromLocationName(Geocoder.java:178)
08-18 14:28:56.026: WARN/System.err(359): at
com.amt.android.garage.Garage.postData(Garage.java:269)
08-18 14:28:56.026: WARN/System.err(359): at
com.amt.android.garage.GarageForm$2.onClick(GarageForm.java:86)
08-18 14:28:56.026: WARN/System.err(359): at
android.view.View.performClick(View.java:2485)
08-18 14:28:56.026: WARN/System.err(359): at
android.view.View$PerformClick.run(View.java:9080)
08-18 14:28:56.036: WARN/System.err(359): at
android.os.Handler.handleCallback(Handler.java:587)
08-18 14:28:56.036: WARN/System.err(359): at
android.os.Handler.dispatchMessage(Handler.java:92)
08-18 14:28:56.036: WARN/System.err(359): at
android.os.Looper.loop(Looper.java:130)
08-18 14:28:56.036: WARN/System.err(359): at
android.app.ActivityThread.main(ActivityThread.java:3683)
08-18 14:28:56.036: WARN/System.err(359): at
java.lang.reflect.Method.invokeNative(Native Method)
08-18 14:28:56.036: WARN/System.err(359): at
java.lang.reflect.Method.invoke(Method.java:507)
08-18 14:28:56.036: WARN/System.err(359): at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
08-18 14:28:56.046: WARN/System.err(359): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
08-18 14:28:56.046: WARN/System.err(359): at dalvik.system.NativeStart.main(Native
Method)
There is a problem recently with android devices and the geocoder not working:
http://code.google.com/p/android/issues/detail?id=38009
A reboot seems to fix the issue
You will get this error occasionally if the GeoCoding provider fails and is unable to geocode your location.
See these relevant posts:
Geocoder.getFromLocation throws Exception
Geocoder.getFromLocation throws IOException on Android emulator
If this is not the case, make sure you have the Internet permission in your Manifest:
<uses-permission android:name="android.permission.INTERNET" />
Try updating Location first. Like below
locationManager.requestLocationUpdates(bestProvider, 20000, 1, this);
refer to here.

Categories

Resources