原文 Xamarin.Android - 储存数据于Windows Azure

如何将Xamarin.Android 与Windows Azure做结合,将Android APP上的数据丢到云端去储存。

1. 在Windows Azure上建立一个Mobile Service
首先到Windows Azure上去建立一个Mobile Service。这边我建立了一个for Android的Mobile Service。
2. 在Mobile Service上面新增一个item数据库

2.1 接下来我们要在刚刚建立的Mobile Service上面建立一个储存数据的Table。 这里可以使用Windows Azure上的模板,点选到Azure上的Android,选择底下的 [CONNECT AN EXISTING ANDROIP APP]。

2.2 在展开的网页里面会看到一个选项,[Create Item table], 点这个绿色的按钮Windows Azure会帮我们在云端上面建立一个数据库。到目前为止在Windows Azure上的准备已经完成了。

2.3 新增完成后,可以在Windows Azure上面看到我们新增出来的Table,这个Table里面有两个字段,分别是 id还有Text。

3. 下载安装Azure Mobile Service

在Xamarin网站上下载MobileService组件,将档案下载到你的计算机端后,解开压缩。,后续要在我们的Android项目中引用MobileService档案里面的

Microsoft.WindowsAzure.MobileService.Android.dll档案。http://components.xamarin.com/view/azure-mobile-services/

4. 撰写程序将数据写进item Table
4.1 开启Visual Studio 2012,去新增一个Android专案。
4.2 把刚刚下载MobileService组件里面的Microsoft.WindowsAzure.MobileServices.Android.dll组件加入参考。

4.3 在专案里点MainActivity.cs档案两下,开启编辑画面,这边建立一个Item Class。这个是稍后要用来储存档案到Windows Azure的对应类别。

public class Item {
public int Id;
public String Text;
}

4.4 接着在OnCreate事件中,我们建立以下程序。

//MobileService主要是用来连接到你的Windows Azure。连接的url可以在Windows Azure上的

// [CONNECT AN EXISTING ANDROIP APP]页面里找到你的URL网址。

mClient = new MobileServiceClient(
"https://benlutodolistforandroid.azure-mobile.net/",
"KRyAYJbLgxMDaKHdLaeIh88"
);
//建立一个Item的对象实体,然后储存你要储存的数据到item对象的Text属性。
Item item = new Item();
item.Text = "Awesome";

//呼叫mClient.GetTable方法来取得Table,并且指定型别为Item。接着同步数据到Windows Azure。
var test = mClient.GetTable<Item>();
test.InsertAsync (item);

5. 编译执行程序。
因为我们把写入Windows Azure的程序写在Oncreate事件里面,所以当这只APP被加载执行后, 就会触发同步数据库的事件
6. 浏览Windows Azure上的数据库
可以看到数据已经被写入到里Mobile Service下的item Table。

(10)Xamarin.Android - 储存数据于Windows Azure的更多相关文章

  1. [Xamarin.Android] 結合Windows Azure與Google cloud message 來實現Push Notification (转帖)

    這一篇要討論如何使用Xamarin.Android 整合GCM以及Windows Azure來實作Android手機上的推播通知服務. 這篇文章比較著重概念的部分,在開始讀這篇之前,也可以先參考一下X ...

  2. 微软开放技术开发了适用于 Windows Azure 移动服务的开源 Android SDK

     发布于 2014-02-10 作者 陈 忠岳 为进一步实现连接微软与非微软技术的目标,微软开放技术有限公司开发了适用于 Windows Azure 移动服务的 Android SDK,由Scot ...

  3. Windows Azure公有云服务相关方案

    http://www.cnblogs.com/sennly/p/4139675.html 1.公有云平台服务简介 Windows Azure 是一个灵活而开放的云平台,通过该平台,您可以在数据中心快速 ...

  4. Windows Azure入门教学系列 (九):Windows Azure 诊断功能

    本文是Windows Azure入门教学的第九篇文章. 本文将会介绍如何使用Windows Azure 诊断功能.跟部署在本地服务器上的程序不同,当我们的程序发布到云端之后,我们不能使用通常的调试方法 ...

  5. Windows Azure 安全最佳实践 - 第 3 部分:确定安全框架

    构建云应用程序时,安全始终是计划和执行Windows Azure的首要核心因素.第 1 部分提出安全是一项共同责任,Windows Azure为您的应用程序提供超出内部部署应用程序需求的强大安全功能. ...

  6. Windows Azure 安全最佳实践 - 第 2 部分:Azure 提供哪些现成可用的安全机制

    在WindowsAzure安全最佳实践 - 部分:深度解析挑战防御对策中,我介绍了威胁形势以及在您的应用程序中采用深度防御的计划. 在本部分中,我将说明 Windows Azure的安全是一项共同责任 ...

  7. [转]Windows Azure安全概述

    本文转自:http://blogs.msdn.com/b/azchina/archive/2011/03/06/windows_5f00_azure_5f00_security_5f00_overvi ...

  8. Windows Azure 网站:应用程序字符串和连接字符串的工作原理

    编辑人员注释:本文章由 Windows Azure 网站团队的首席项目经理 Stefan Schackow 撰写. Windows Azure 网站上有一个方便的功能,即开发人员可将 Azure 中的 ...

  9. Windows Azure 社区新闻综述(#74 版)

    欢迎查看最新版本的每周综述,其中包含有关云计算和 Windows Azure 的社区推动新闻.内容和对话.以下是本周的亮点. 文章.视频和博客文章 ·   Azure CDN:吸取的宝贵经验(10 月 ...

随机推荐

  1. ZRender源码分析3:Painter(View层)-上

    回顾 上一篇说到:ZRender源码分析2:Storage(Model层),这次咱看来看看Painter-View层 总体理解 Painter这个类主要负责MVC中的V(View)层,负责将Stora ...

  2. Android.Hack.02_Animations

    #01# TextView 和 ImageView TextView和Imageview切换卡顿,为了实现更好的切换,可以用动画来实现,系统自带的TextViewSwitcher 和ImageView ...

  3. python计算md5值

    from hashlib import md5 m = md5(') print m.hexdigest()

  4. AsyncTask详解

    http://blog.csdn.net/liuhe688/article/details/6532519 在Android中实现异步任务机制有两种方式,Handler和AsyncTask. Hand ...

  5. c# xml操作类

    using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Xm ...

  6. C++字符串之一(字符表示)

    在C++中有两种类型可以用于表示字符,char和wchar_t. 但是字符串格式的标准却有很多种,如ASCII,UTF8,UTF16,UTF32等等.字符串的格式和char/wchar_t 的关系是什 ...

  7. MultiByteToWideChar和WideCharToMultiByte用法详解, ANSI和UNICODE之间的转换

    //========================================================================//TITLE://    MultiByteToW ...

  8. STL 统计vector容器中指定对象元素出现的次数:count()与count_if()算法

    1 统计vector向量中指定元素出现的次数:count()算法 利用STL通用算法统计vector向量中某个元素出现的次数:count()算法统计等于某个值的对象的个数. #include &quo ...

  9. 公司需求知识自学- Hashtable简单应用

    定义表 Hashtable tblNames = new Hashtable(); 添加key,value键值对 tblNames.Add("A","a"); ...

  10. [置顶] 编辑框Editext光标最后显示

    [MainActivity] package com.example.testeditext; import android.os.Bundle; import android.app.Activit ...