|
1 | 1 | ## Goals |
2 | 2 |
|
3 | | -1. Learn how to implement an Android app which connects, using __GCM__, |
| 3 | +1. Learn how to implement an Android app which utilises __GCM__, |
4 | 4 | to a server-side app. |
5 | 5 | 2. Learn how to make a server-side app with a __REST__ interface and |
6 | 6 | connections to GCM. |
7 | 7 |
|
8 | | -This project is divided in two parts: the Android client and the server app. |
| 8 | +This project is divided into two parts: the Android client and the server app. |
9 | 9 | My own motivations for this project is to learn how to make a server side |
10 | 10 | app. I already know how to make Android apps but know very little about |
11 | | -web programming. So this will be outside of my comfort zone. |
| 11 | +web programming. So this will be outside of my comfort zone. I have used |
| 12 | +_REST_ interfaces plenty, but never implemented one before. Likewise, |
| 13 | +I am familiar with _GCM_ but have only seen crappy sample implementations |
| 14 | +so far. |
12 | 15 |
|
13 | | -I have the following requirements for the project: |
| 16 | +I stipulate the following requirements for the projects: |
14 | 17 |
|
15 | 18 | __Serverside:__ |
| 19 | +* Should be written in _Python_ |
16 | 20 | * Have a __REST__ api |
17 | 21 | * Use __GCM__ |
18 | 22 | * Require login but don't handle passwords |
19 | 23 |
|
20 | 24 | __Androidside:__ |
21 | 25 | * No passwords |
| 26 | +* All network stuff should be done in a _SyncAdapter_ |
22 | 27 | * Get push updates through __GCM__ |
23 | | -* Initial full sync on install using __REST__ |
| 28 | +* Full syncs using __REST__ |
24 | 29 |
|
25 | | -## Server app |
26 | | -Step 1 will be to construct an app we can deploy on a webserver somewhere. |
| 30 | +## Can't I read all this somewhere already? |
| 31 | +Yes you can! There are alot of documents, tutorials, sample code |
| 32 | +and help you can get online, many times straight from Google themselves! |
| 33 | +The problem is that there is __alot__ of documents, tutorials etc. |
| 34 | +And they all __focus on one thing__. Either it's a document about |
| 35 | +making a _SyncAdapter_, or it's a tutorial on _GCM_, or a document |
| 36 | +about making a _WebApp_. |
| 37 | + |
| 38 | +It's all about __context__. Maybe I haven't looked hard enough, but |
| 39 | +to my eyes no one gives you the big picture and the technical details. |
| 40 | +Google's own documents on _GCM_ is a prime example: they talk at length |
| 41 | +about the structure of the system, and give you plenty of sample code |
| 42 | +for the client side, but are incredibly vague on the server bit. They |
| 43 | +mention the requirement of an _application server_ but give no help |
| 44 | +in creating one. |
| 45 | + |
| 46 | +Again, it's all about __context__. The _GCM_ docs focus on how to implement |
| 47 | +the _GCM_ bits, so it's not that weird that it doesn't go into newbie |
| 48 | +hints on application servers. But no one else seems to do that either. |
| 49 | +Another thing is that there are a ton of documents that are out-dated. |
| 50 | + |
| 51 | +For example, stay away from all server-libraries developed by Google. |
| 52 | +The Java versions might be good, but the Python versions __SUCK DONKEY BALLS__. |
| 53 | +Python __IS NOT AN EXCUSE TO USE GLOBAL VARIABLES ****ING EVERYWHERE__. |
| 54 | + |
| 55 | +In short, I will attempt to deliver both the |
| 56 | +_big picture_ and the _nitty gritty details_ in this project that no one |
| 57 | +else seems keen on writing down. |
| 58 | + |
| 59 | +## Target audience |
| 60 | +This is not a tutorial for someone looking to write their first Android |
| 61 | +app or program. I assume that you have worked with Android before. I also |
| 62 | +expect that you are familiar with some concepts, at least in theory, like |
| 63 | +_REST APIs_ or _Sqlite_. I do try to explain the idea behind the |
| 64 | +implementations but I will not go into detail as to why I had that particular |
| 65 | +idea over another. |
| 66 | + |
| 67 | +## Intent |
| 68 | +I do not claim that this code is ready for anything other than a base to |
| 69 | +build upon for your own projects. It is __NOT PRODUCTION READY__. |
| 70 | +People with more expertise than myself can probably improve upon several |
| 71 | +aspects, and I welcome any suggestions/merge requests that can improve |
| 72 | +the project. As I said, when it comes to server apps, I'm also something |
| 73 | +of a newbie. |
| 74 | + |
| 75 | +## Why Python for the server app? |
| 76 | +_Python_ is by far my current favorite language. It takes so much less |
| 77 | +bloat compared to _Java_ to translate an idea into a working implementation. |
| 78 | +Hopefully, I will convince you along the way that _Python_ is awesome. |
| 79 | +Even if you are not familiar with _Python_, I bet that it will be possible |
| 80 | +for you to understand the program completely anyway. Because it's that |
| 81 | +simple. |
| 82 | + |
| 83 | +## Format of the tutorial |
| 84 | +The _READMEs_ go through the construction of the apps step by step. They |
| 85 | +specify what __SHA1__ corresponds to that state in the tutorial. That |
| 86 | +means that you can examine all pieces of the project at that particular |
| 87 | +state by doing: |
| 88 | + |
| 89 | +```shell |
| 90 | +git checkout <sha1> |
| 91 | +``` |
| 92 | + |
| 93 | +Just do this to get back to the normal state |
| 94 | +```shell |
| 95 | +git checkout master |
| 96 | +``` |
| 97 | + |
| 98 | + |
| 99 | +What is particularly useful is that you can do direct comparisons |
| 100 | +to see all changes between one state and the next by doing: |
| 101 | + |
| 102 | +```shell |
| 103 | +git diff <sha1> <sha1> |
| 104 | +``` |
| 105 | + |
| 106 | +And you can show the differences for a particular |
| 107 | +file/folder with: |
| 108 | + |
| 109 | +```shell |
| 110 | +git diff <sha1> <sha1> <filename-or-folder> |
| 111 | +``` |
| 112 | + |
| 113 | +I highly recommend doing it to see exactly what lines of code |
| 114 | +were added to implement some feature. Here's an example |
| 115 | +that would show what was added to enable authentication |
| 116 | +with Google in the server-app: |
| 117 | + |
| 118 | +```shell |
| 119 | +git diff 599d6fda70f 94011e7b6d2 server-app/app.py server-app/google_auth.py |
| 120 | +``` |
| 121 | + |
| 122 | +## Requirements |
| 123 | +You should read the [official docs on GCM](http://developer.android.com/google/gcm/gcm.html) |
| 124 | + |
| 125 | +You also need to create a project in the [Google API console](https://code.google.com/apis/console) |
| 126 | + |
| 127 | +For the purpose of this tutorial, the docs are somewhat confusing in regards |
| 128 | +to what key you need to generate. You need to generate the following |
| 129 | +types of keys: |
| 130 | + |
| 131 | +* Client ID for installed applications ([Guide](https://developers.google.com/+/mobile/android/getting-started)) |
| 132 | +* Simple API Access ([Guide](http://developer.android.com/google/gcm/gs.html)) |
| 133 | + |
| 134 | +The _Simple API key_ will be used by the server to verify the validity of |
| 135 | +authentication tokens generated by the client. To generate the token, the |
| 136 | +clients need the _Client ID for installed apps_, but you won't need a specific |
| 137 | +key in that case since Google will verify the package name of |
| 138 | +the application. You will need the project number in the client though, which |
| 139 | +you can see in the address bar of your browser: |
| 140 | + |
| 141 | +``` |
| 142 | +https://code.google.com/apis/console/#project:8646666293:access |
| 143 | +``` |
| 144 | + |
| 145 | +Where _8646666293_ is your project number. |
| 146 | + |
| 147 | +### Server app |
| 148 | +In this folder I construct an app we can deploy on a webserver somewhere. |
27 | 149 | Go into the _server-app_ folder and see how that's done. |
28 | 150 |
|
29 | | -## Android app |
30 | | -Step 2 will be the Android app. This will be fairly straightforward. Have |
31 | | -a look in _android-client_ for that. |
| 151 | +The server is coded in _Python_ because _Java_ is mostly bloat. |
| 152 | + |
| 153 | +### Android app |
| 154 | +In this folder I implement an android app. This will be fairly straightforward. |
| 155 | +Have a look in _android-client_ for that. |
32 | 156 |
|
33 | 157 | ## Result |
34 | | -No result so far. |
| 158 | +You can download the finished app and try it out for yourself here: |
| 159 | + |
| 160 | +APK LINK TO RELEASES |
35 | 161 |
|
36 | | -When finished, will link to apk and have the server running. |
| 162 | +It connects to a running version of the server-app. |
0 commit comments