Posts

A wired issue of MediaPlayer on Android

Background Our application needs to play mp3 files served by our server. What we used to do is just using MediaPlayer to play that URL. However, there are more and more customers complaint about Music playing being cut off quite frequently. So I had to dig into legacy codes to find out the reason. Reproduce From existing codebase, I could tell our app respects MediaPlayer's   OnErrorListener   and if MediaPlay throw out any Error, app will try to catch them and recover. Unfortunately, we did not receive any exceptions for this part according to our Fabric crashlytics report. Besides that, this bug is not really easy to reproduce.   I knew it must be caused by user's network issue. So I tried Charles proxy and using its throttling feature. However it seems like MediaPlayer would have a special connection after connecting and Charles' throttling can not control that connection. Then I also tried Android Emulator's build-in network status simulation feature. Sti...

Gradle issue - peer not authenticated

When we tried to migrate our Gitlab from Http to Https , we met a problem of Maven Central which was also maintained as a Git repo. peer not authenticated Basically the reason is JVM can not pick up trusted CA from local machine. So we manually trusted it with commands. 1. Get the certificate file (.cer). I am using Mac so I just trusted that certificate through browser and it will be saved in Keychain Access. Then I just export that certificate as .cer file. 2. Copy the .cer file to $JDK_HOME/jre/lib/security folder 3. Run the command keytool - import - alias <alias_of_this_cert> - file < cert_file_name_you_exported . cer > - keystore cacerts - storepass changeit 4. Gradle is able to find dependencies now. NOTE : how to get current JAVA_HOME: /usr/libexec/java_home [-v '1.8'] how to transfer file through ssh: cat {origin file} | ssh {username}@{remote host} "cat - > {target file}"

how to set https ssl proxy for Android debuging with Charles

http://jaanus.com/blog/2012/02/12/debugging-http-on-an-android-phone-or-tablet-with-charles-proxy-for-fun-and-profit/ 1. using Android default browser access  http://charlesproxy.com/charles.crt 2. in popup dialog type in the certificate name. I just name it "Charles" 3. open charles and set the android wifi using laptop or pc as proxy. 4. select the target ip as accepting ssl proxy.

How to add pre-receive hook in GitLab

Image
Recently we decided to move our git repo to local git server so we chose GitLab. During weeks use GitLab it was really convenient. Until one day we have a thought about checking code style before push.  Basically Git support 2 kinds of hooks. One is Client side and the other is from Server side http://git-scm.com/book/en/Customizing-Git-Git-Hooks In terms of checking code style we can do both on Client and Server side.  However we want this rules be more STRICT :D, so we decided to make it from Server side . So here is problem! After investigation we found GitLab actually changed quite a lot from Gitorious. Especially Gitlab uses Gitlab-Shell to wrapper the Git commands. So when we found "Hooks" folder what we can get is like this:    ONLY ONE "UPDATE" . If you open it you will found quite simple codes:    So check GitlabUpdate in ../lib/  And if you change the codes to exit with "1", all the push request will be rejecte...

How to write Gradle Plugins with Groovy for Android

Image
Since Android Studio being released,  I could always find that Google announce that Gradle is better than Maven and Ant. Especially it supports Groovy as script language natively. However I could not get chance to try it. Recently our project requires us to implement CI and something else. So I got chance to learn it more. Firstly I need to know how to create a customised Gradle Task using Groovy. I tried building some simple "Hello world " tasks inside of build.gradle file. They all work fine. But once I tried to implement some more complicated ones which needs importing some other libraries, it will complain can not import. So I recheck the doc from Gradle. There is another way to create a standalone plugin library. http://www.gradle.org/docs/current/userguide/custom_tasks.html So I followed the doc to create mine one. 1. Create Gradle project using Intellij 2. Add framework support -> Groovy 3. Create the source structure like this. 4. Change the bui...

Android how to keep the white space inside of string.xml file

Quick solution for maintaining white space inside of string.xml file \u0020

solve one issue because of thread safe httpclient

I was using HttpClient to handle the http request and response. Previously I always debug on latest phones which are upper 4.0 everything works fine. One day I tried on my older phone Moto Defy running 2.3.7 from Cyanogenmod . There was one issue when I tried to post an image . I got the log : Invalid use of SingleClientConnManager: connection still allocated. or Caused by: java.lang.IllegalStateException: No wrapped connection. or Caused by: java.lang.IllegalStateException: Adapter is detached. Searched in stackoverflow normally it is because of accessing single instance of HttpClient in different thread or did not close InputStream of httpresponse.  Mine issue is the first one.  So I learnt one solution to get a thread safe httpclient. public static DefaultHttpClient getThreadSafeClient () { DefaultHttpClient client = new DefaultHttpClient (); ClientConnectionManager mgr = client . getConnectionManager (); HttpParams para...