我建个android app和Windows Azure的Mobile Service配合,以实现会员注册的功能,实际十分简单,微软家的东西真心好用

首先新建个Mobile Service

New->Mobile Service->Create之后弹出下图的对话框

URL就自定义一个,如果有人注册了会报错,换个就好,database新建还是使用已存在的都可以,新建之后会多一步让你输入要新建的数据库的名称和密码,backend就选Javascript,点击箭头下一步

使用现存的会让你输入密码,建立完成,点击主界面左侧的Mobile service,出现下图

我这里选“连接一个已存在的android app”,其实现在下面微软的教程就放在那里了

在自己的android app中确保build.gradle(project:你自己的工程名)里面有:

  1. repositories {
  2. jcenter()
  3. }

build.gradle(project:Model:app)中添加windows azure sdk,就是把这几句添加到dependencies里去:

  1.    compile 'com.google.code.gson:gson:2.3'
  2. compile 'com.google.guava:guava:18.0'
  3. compile 'com.microsoft.azure:azure-mobile-services-android-sdk:2.0.3'
  4. compile (group: 'com.microsoft.azure', name: 'azure-notifications-handler', version: '1.0.1', ext: 'jar')

在自己的实现MobileService功能代码中添加:

  1. private MobileServiceClient mClient;
    private ProgressBar mprogressBar;
  1.   try {
  2. mClient=new MobileServiceClient("你的URL",
  3. "你的KEY",
  4. this).withFilter(new ProgressFilter());
  5.  
  6. mStudentTable=mClient.getTable(Student.class);
  7. } catch (MalformedURLException e) {
  8. e.printStackTrace();
  9.  
  10. createAndShowDialog(new Exception("移动服务发生错误,检查URL和Key试试"), "Error");
  11. }
  1. private class ProgressFilter implements ServiceFilter {
  2.  
  3. @Override
  4. public ListenableFuture<ServiceFilterResponse> handleRequest(
  5. ServiceFilterRequest request, NextServiceFilterCallback next) {
  6.  
  7. runOnUiThread(new Runnable() {
  8.  
  9. @Override
  10. public void run() {
  11. if (mprogressBar != null) mprogressBar.setVisibility(ProgressBar.VISIBLE);
  12. }
  13. });
  14.  
  15. SettableFuture<ServiceFilterResponse> result = SettableFuture.create();
  16. try {
  17. ServiceFilterResponse response = next.onNext(request).get();
  18. result.set(response);
  19. } catch (Exception exc) {
  20. result.setException(exc);
  21. }
  22.  
  23. dismissProgressBar();
  24. return result;
  25. }
  26. }
  1. private void dismissProgressBar() {
  2. runOnUiThread(new Runnable() {
  3.  
  4. @Override
  5. public void run() {
  6. if (mprogressBar != null) mprogressBar.setVisibility(ProgressBar.GONE);
  7. }
  8. });
  9. }

上面代码中的“你的URL”和“你的KEY”替换成你自己新建的Mobile Service的URL和KEY,其实在现在向导里面有的,没有单击上面的“DASHBOARD”,你的URL和key如图

关于KEY,点击MANAGE KEYS,等一秒,复制那个Application key。

接下来,定义那个要传送的实体类Student

  1. import com.google.gson.annotations.SerializedName;
  2.  
  3. import java.util.Objects;
  4.  
  5. /**
  6. * Created by chen on 2015/9/19.
  7. */
  8. public class Student {
  9.  
  10. @SerializedName("id")
  11. private String mID;
  12.  
  13. @SerializedName("stuid")
  14. private String mStuID;
  15.  
  16. @SerializedName("name")
  17. private String mName;
  18.  
  19. @SerializedName("sex")
  20. private String mSex;
  21.  
  22. @SerializedName("qq")
  23. private String mQQ;
  24.  
  25. //Constructor
  26. public Student(){
  27.  
  28. }
  29.  
  30. public Student(String id,String stuid,String name,String sex){
  31. this.setID(id);
  32. this.setStuID(stuid);
  33. this.setName(name);
  34. this.setSex(sex);
  35. }
  36.  
  37. public void setID(String id) {
  38. this.mID = id;
  39. }
  40.  
  41. public void setName(String name) {
  42. this.mName=name;
  43. }
  44.  
  45. public void setSex(String sex) {
  46. this.mSex = sex;
  47. }
  48.  
  49. public void setStuID(String stuID) {
  50. this.mStuID = stuID;
  51. }
  52.  
  53. public void setStuQQ(String stuQQ){this.mQQ=stuQQ;}
  54.  
  55. @Override
  56. public String toString(){return getName();}
  57.  
  58. public String getName(){return mName;}
  59.  
  60. public String getID(){return mID;}
  61.  
  62. public String getStuID(){return mName;}
  63.  
  64. public String getSex(){return mSex;}
  65. }

注意:实体类中类似@SerializedName("id")里面的“id”要和接下在azure管理中定义的Column名字一致,官方文档中说,只要一致mobile service就会自己解析json并将其对应存储到数据库中。

下面就定义数据库,如图,在azure的管理界面上,如图点DATA,选自己的数据库,新建张表,表中的Column要和上面的实体类一致,最终的效果应该这样

运行安卓客户端,success!

Windows Azure之Mobile Service的更多相关文章

  1. [Windows Azure] How to use the Windows Azure Blob Storage Service in .NET

    How to use the Windows Azure Blob Storage Service in .NET version 1.7 version 2.0 This guide will de ...

  2. 跟我学Windows Azure 四 Cloud Service中的WebRole与WorkRole,及他们之间的通信

    Cloud Service 中WebRole就相当与我们的WebSite,而WorkRole相当与我们在服务器上写了个Windows Service,站在高可用的角度上来讲,Cloud Service ...

  3. [iOS]使用Windows Azure來做iOS的推播通知 (转帖)

    這一篇我們用Windows Azure 的Mobile Service 來實作iOS的推播通知,底下我們分成三個階段來探討如何實作推播通知的服務: 第一階段: 開啓你的Windows Aure服務   ...

  4. Windows Azure Service Bus Topics实现系统松散耦合

    前言 Windows Azure中的服务总线(Service Bus)提供了多种功能, 包括队列(Queue), 主题(Topic),中继(Relay),和通知中心(Notification Hub) ...

  5. Windows Azure Service Bus Notification Hub推送通知

    前言 随着Windows Azure 在中国的正式落地,相信越来越多的人会体验到Windows Azure带来的强大和便利.在上一篇文章中, 我们介绍了如何利用Windows Azure中的Servi ...

  6. Windows Azure Service Bus (1) 基础

    <Windows Azure Platform 系列文章目录> 我们在基于Windows Azure进行云端开发的时候,云端的软件通常都需要与其他软件进行交互.这些其他软件可能包括其他In ...

  7. windows azure Vm、cloud service、web application 如何选择可用的服务

    windows azure 的web应用和虚拟机都经常用.我们经常把我们的网站部署上去.一般选择web应用或者开一个虚拟机.开一个虚拟机就会按照虚拟机的使用时间进行计费. 那么我们选择web部署在哪里 ...

  8. [Windows Azure] How to use the Queue Storage Service

    How to use the Queue Storage Service version 1.7 version 2.0 This guide will show you how to perform ...

  9. [Windows Azure] How to use the Table Storage Service

    How to use the Table Storage Service version 1.7 version 2.0 This guide will show you how to perform ...

随机推荐

  1. 学习OpenCV研究报告指出系列(二)源代码被编译并配有实例project

    下载并安装CMake3.0.1       要自己编译OpenCV2.4.9的源代码.首先.必须下载编译工具,使用的比較多的编译工具是CMake. 以下摘录一段关于CMake的介绍: CMake是一个 ...

  2. 【BZOJ 1038】[ZJOI2008]瞭望塔

    [题目链接]:http://www.lydsy.com/JudgeOnline/problem.php?id=1038 [题意] [题解] 可以看到所有村子的瞭望塔所在的位置只会是在相邻两个村子所代表 ...

  3. Apache POI Word基本使用

    Apache POI Word 1.什么是Apache POI? Apache POI是一个流行的API,使用Java程序创建,修改和显示MS-Office文件. 它是由Apache Software ...

  4. hdu1845 Jimmy’s Assignment --- 完整匹配

    意甲冠军: 它需要一个特殊的图,以找到最大匹配.该图的特征是:无向图,度的每个节点3.这是一个双边连接组件(the graph is 2-edge-connected (that is, at lea ...

  5. google地图API的简单使用

    <div id="contact_container" style="width:700px;height:600px;"></div> ...

  6. 阐述php(五岁以下儿童) 注意事项和使用功能

    1.函数声明 <?php /** * function 函数名(參数1, 參数2.... ){ * 函数体; * 返回值; * } */ $sum = sum(3, 4); echo $sum; ...

  7. Win10忘记ubuntu子系统密码

    原文:Win10忘记ubuntu子系统密码 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/wf19930209/article/details/80 ...

  8. 假设做一个循环滚动UIScrollView

    先上效果图: 首先初始化: - (void)viewDidLoad { //加入最后一张图 用于循环 int length = 4; NSMutableArray *tempArray = [NSMu ...

  9. 使用Wireshark抓取SNMP Trap包

    Wireshark SNMP Trap 过滤关键字:snmp && udp.dstport == 162

  10. HDU 5073 Galaxy(Anshan 2014)(数学推导,贪婪)

    Galaxy Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total S ...