In previous posts, I showed you how to get/post data to ASP.NET Web API service. However, until now, I only used JSON for communicating between server and client and what about for binary data? For example, uploading files to ASP.NET Web API? How should the controller work and which kind of HTTP request/HTTP format should the Android client send to server? In this blog post, I will show you a simple way to transfer binary data. In the demo, I have 2 components : web service and android client. Unlike the other post, for this one, unfortunately, I don’t have any sample web service (online over internet) for you to test. I don’t own any windows server (neither VPS nor dedicated server :() therefore I can’t host any web service allowing file uploading.
Let’s start with a question. When was the last time you played a song offline at your computer? For me, It’s long,loong,looong… time ago. Since the boom of music websites, I just choose one provider, create my favorite playlist and listen to music online. I don’t have any CD or .mp3 song at my local computer anymore, except that there are still a lot of songs in my Ipod but I don’t know where he is right now 😕 and that’s … bad. If something wrong happens with the website, my song will go with the wind. Moreover nowadays, in the dangerous internet, I doubt all of apps (if they are harmful) and consider a lot every time I install an app on my Android smartphone. So I always try to write the app or software myself if they aren’t complex. For this case, for my favorite songs, I decide to write a very simple media player connecting to my web service, playing my own song and I don’t have to worry anymore about the problem mentioned above. That’s is the concept. Next, I would like to show my media player works, if you want to improve it, go on!
If you’re working with .NET, maybe you’re already familiar with the concepts of dependency injection and MVVM (Model-View-ViewModel) pattern. Some of popular dependency injection containers for .NET are Castle Windsor, Ninject or Unity… They are all good frameworks, it just depends on which you prefer. For example, I use Castle Windsor at company and Ninject at home so that I can understand and use both of frameworks. It’s just the matter of favorite. The MVVM pattern was introduced years ago when WPF came to market. This pattern makes use of data binding structure of WPF and helps programmer to separate the view completely from logic layer. For more details about this pattern you can read some articles on my site about MVVM. Today, I will discuss again about these concepts, however not for .NET application, but I would like to show how we can apply these concepts into Android app. The example I use in this post is a De-De-Dictionary app. In this app, I can add German vocabulary with his explanation (also in German :)) through a user interface or look up for a vocabulary. Nothing special than a real dictionary book.
If you are searching to a coordinate (such as street, house number, location…) in Google Maps , you’ll see that there are more information about public places near by such as airport, cafe, restaurant, store… This information is really helpful, for example, if I want to move to a new apartment, I would like to check if the public transport is near by, any supermarket is available, playground for my children is not too far… with Google Maps you’ll get all information. Or another example, if I’m on highway and too tired because of driving, I can find any motel/hotel near by my current location so that I can drop in and take a rest. Therefore today I would like to make a small demo to show how we can show Google Places on our Android smartphone or integrate this feature to our apps.
Integrating Google Maps (or any map service) is always a nice feature for our applications, but it seems to be “complicated” for integrating Google Maps because Google Maps is not officially supported in emulator because lacking of Google Play Service. That forces us to use a real device during developing app. For me, not nice. So in this post, I would like to show step by step how I configure my emulator so that a Google Maps app can be installed on there. To make such an emulator, we have to use a set of correct settings/files. If not, it won’t work. So you have to set all settings like mine. My emulator targets on Android 4.2.2 – API Level 17.
Linking to social networks may be one of special features of your program. Today I’d like to make a small demo to make a tweet in Twitter from Android. The demo will use oAuth to authenticate user with Twitter and allow him to tweet when authentication is successful. The app won’t make any authentication with username and password, the authentication process will happen at Twitter website. When the process finishes, a successful access token will be returned to notify if user entered correct log in data. We can store this token for later use without requiring user to log in again.
Pushing message from the server to client so that client doesn’t have to send the request to the server periodically is not a new concept anymore. Earlier when then client wants to check if the server wants to send something to him, he has to send dummy request to server repeatedly to ask for notifications. Although the server has nothing new, he is still overloaded because of handling these kinds of requests. Actively pushing message from the server to client will save him from unnecessary requests of clients. In this concept, the client will connect to the server through a channel and wait there for a new message. When the server wants to notify a client, he just uses the current active channel between him and client, then sends a message through it. The client receives notification and handles it. Server and client don’t have to send ping-pong message to communicate, all they have to do is building up an active channel between them and communicating through that channel.
In my previous posts, I discussed how we can consume the ASP.Net Web API with RestSharp and HttpClient. In this small one, I would like to show how we can make a demo application in Android consuming ASP.Net Web API service. To save time, I already prepare a sample REST web service made by ASP.NET Web API with only one resource at http://restwebserviceforandroid.apphb.com/api/products. You can access the service without any authentication for your testing purposes. On the server, I use Entity Framework to connect to a SQL Server behind with following structure
If you are trying to call web service within Android emulator, maybe you would like to see how your real HTTP request looks like and was sent to server. Of course there are a lot of ways to hook network interface such as using Wireshark, Microsoft Network Monitor,… However these tools provide low-level-interfaces with packet capturing which aren’t appropriate for TCP/IP data analyzing. Therefore, in this small blog post, I’ll summarize how to configure Fiddler so that he can capture all traffic going through Android emulator. Fiddler can parse JSON/XML format in readable form so that we can validate input/output data in HTTP request.