Android Framework(I)Android Spring Json

1. Backgroud of Spring Android and Json
First, learn from spring.
Spring Mobile project that provides extensions to Spring MVC for developing mobile web apps.
Spring Android project that supports the development of native Android clients that communicate with spring-based back-ends.

Spring Mobile
1. A HandlerInterceptor that uses a DeviceResolver to detect the Device that originated the current HttpServletRequest.
2. The ability to inject the detected Device into @Controller methods and view templates to vary logic by device type.

Interceptor /WEB-INF/spring/appServlet/servlet-context.xml
<interceptors>
<beans:bean class="org.springframework.mobile.device.mvc.DeviceResolvingHandlerInterceptor" />
</interceptors>

JSP template:
Please try again<c:if test="${!currentDevice.mobile}"> or <a href="<c:url value="/signup" />">sign up</a></c:if>

Tiles-based page layout:
<definition name="page" templateExpression="/WEB-INF/layouts/${currentDevice.mobile ? 'mobile/' : 'standard/'}page.jsp"

Spring Android
The client side need to exchange data with the server over HTTPS via REST. We need to store username and password credentials on the
device itself, we opted for OAuth. RestTemplate for the REST API calls, and Spring Security for the OAuth client.

RestTemplate restTemplate = new RestTemplate(new CommonsClientHttpRequestFactory());
Event event = restTemplate.getForObject("https://myapp.com/event/{name}", Event.class, "springone2gx");

Greenhouse project URL
http://www.springsource.org/greenhouse
Run the green house locally
http://www.springsource.org/greenhouse/guide

Web APP
get the source codes
git clone https://github.com/SpringSource/greenhouse.git greenhouse

Greenhouse for Android
get the source codes
git clone https://github.com/SpringSource/greenhouse-android.git greenhouse-android

>vi pom.xml
add sdk path and platform to them

<sdk>
<path>/home/luohua/tools/android-sdk-linux_x86</path>
<platform>7</platform>
</sdk>
<emulator>
<avd>G7</avd>
</emulator>

Another example:
svn checkout http://geonames-android.googlecode.com/svn/trunk/ geonames-android-read-only

spring android samples:
git clone git://github.com/SpringSource/spring-android-samples.git spring-android-samples

spring android source:
git clone --recursive git://github.com/SpringSource/spring-android.git spring-android

2. Spring Android and Maven

Maven Configuration
Maven Android Plugin
Android applications are deployed to the device as an apk file, not a jar. You must specify this in the packageing configuration.
<packaging>apk</packaging>
<build>
...snip...
</build>
<repositories>
...snip...
</repositories>

Build Enviroment
>vi /etc/enviroment
ANDROID_HOME=/home/luohua/tools/android-sdk-linux_x86
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/home/luohua/tools/android-sdk-linux_x86/tools:
/home/luohua/tools/android-sdk-linux_x86/platform-tools"

Configure an Android Virtual Device
...snip...

Sample Application
>git clone git://git.springsource.org/spring-mobile/samples.git spring-mobile-samples

>cd spring-android-showcase
start the server side
>cd server
>mvn install
>cp /home/luohua/.m2/repository/org/springframework/android/spring-android-showcase-server
/1.0.0-BUILD-SNAPSHOT/spring-android-showcase-server-1.0.0-BUILD-SNAPSHOT.war
/home/luohua/tools/apache-tomcat-7.0.12/webapps/spring-android-showcase-server.war
>bin/startup.sh
verify the server side with this URL
http://localhost:8080/spring-android-showcase-server/

run the Android Client
modify the pom.xml <sdk><path><platform><emulator><avd>
>mvn clean install
>mvn android:emulator-start

problem here, the window of the emulator is too big
solution:
>telnet localhost 5554
>window scale 0.65
>quit

>mvn android:deploy

Problem: pkg: /data/local/tmp/spring-android-showcase-client.apkFailure [INSTALL_FAILED_OLDER_SDK]
That is only because of the version.
verify the AndroidManifest.xml
<uses-sdk android:minSdkVersion="4" />

modify the pom.xml:
<platform>10</platform>
<avd>10</avd>

I find an app named spring-android

>adb logcat

we can see the logs.

3. Spring Android and Eclipse IDE
Installing Plugins using the Eclipse Marketplace Client
Help ----> Eclipse Marketplace...
m2eclipse-android click 'Go' and 'Install'
egit click 'Go' and 'Install'

And in another way, we can install this manly
ADT
https://dl-ssl.google.com/android/eclipse

MAVEN2
http://m2eclipse.sonatype.org/sites/m2e

MAVEN2-ANDROID
https://svn.codespot.com/a/eclipselabs.org/m2eclipse-android-integration/updates/m2eclipse-android-integration/

Fetch the Sample Project
>git clone git://git.springsource.org/spring-mobile/samples.git spring-mobile-samples

create a Android Project in existing directory of spring-android-showcase/client
enable mavenmanagement

create a Dynamic Web Project in existing directory of spring-android-showcase/server
enable mavenmanagement


references:
http://www.makeurownrules.com/rest-spring-maven-android
http://code.google.com/p/geonames-android/
http://blog.springsource.com/2010/12/17/spring-android-and-maven-part-1/
http://www.springsource.org/spring-android




更多相关文章

  1. 代码中设置drawableleft
  2. android 3.0 隐藏 系统标题栏
  3. Android开发中activity切换动画的实现
  4. Android(安卓)学习 笔记_05. 文件下载
  5. Android中直播视频技术探究之—摄像头Camera视频源数据采集解析
  6. 技术博客汇总
  7. android 2.3 wifi (一)
  8. AndRoid Notification的清空和修改
  9. Android中的Chronometer

随机推荐

  1. Android(安卓)去掉toolbar阴影
  2. android 获取联系人和短消息信息
  3. android 邮件地址正则表达式
  4. Android之ScrollView嵌套ListView解决工
  5. Android(安卓)文件操作
  6. android客户端与web服务端的数据通信
  7. android studio 导入其他project遇到 Cou
  8. Android(安卓)Error: java.lang.IllegalA
  9. Android(安卓)Facebook分享功能实现
  10. Android(安卓)RecyclerView 子条目(item)嵌